es常用curl命令
端口:
EsMaster: 24148
EsNode1: 24100
EsNode2: 24102
?
_cluster命令???
查詢集群狀態(tài)命令:
curl -XGET -–tlsv1.2?–negotiate -k -u :?"https://ip:port/_cluster/health?pretty"
查詢ES全局狀態(tài)
curl -XGET?–tlsv1.2?–negotiate -k -u : 'https://ip:port/_cluster/stats?pretty'
解釋分片,查看分片狀態(tài)
curl -XGET --negotiate -k -u : "https://127.0.0.1:24100/_cluster/allocation/explain?pretty"?-H 'Content-Type:application/json'?-d '{
? ? "index": "indexname",
? ? "shard": 17,
? ? "primary": true
}'
重新分配主分片
curl -XPOST --tlsv1.2 --negotiate -k -u : "https://127.0.0.1:24148/_cluster/reroute?pretty" -H 'Content-Type:application/json' -d '{
????"commands": [{
???????"allocate_stale_primary": {
???????????"index": "index1",
???????????"shard": 2,
???????????"node": "EsNode1@189.39.172.103",
? ? ? ? ? ? ? ? ? ? ? ? "accept_data_loss":true
?
???????}
????}]
}'
?
?
_cat命令???
?
查詢所有索引:
curl -XGET --tlsv1.2--negotiate -k -u : "https://ip:port/_cat/indices?pretty"
查詢ES實(shí)例列表
curl -XGET --tlsv1.2 --negotiate -k -u : 'https://ip:port/_cat/nodes/?v'
查看_cat/nodes接口的幫助信息:?
curl -XGET --tlsv1.2 --negotiate -k -u : 'https://ip:port/_cat/nodes?help'
查詢所有esnode的指定參數(shù)列的值,包括堆內(nèi)存等
curl -XGET --tlsv1.2 --negotiate -k -u : 'https://ip:port/_cat/nodes?v&h=http,dt,du,dup,hm,hc,hp,fdm,fdc,fdp,cpu'
?
查詢es集群是否健康
curl -XGET --tlsv1.2 --negotiate -k -u : 'https://ip:port/_cat/health?v'
查詢es集群index的整體數(shù)據(jù)量
curl -XGET --tlsv1.2 --negotiate -k -u : 'https://ip:port/_cat/indices?v'
查詢集群線程池使用情況
curl -XGET --tlsv1.2 --negotiate -k -u : 'https://ip:port/_cat/thread_pool?v'
查詢集群bulk操作的線程數(shù)量
curl -XGET --tlsv1.2 --negotiate -k -u : 'https://ip:port/_cat/thread_pool/bulk?v'
curl -XGET --tlsv1.2 --negotiate -k -u : 'https://ip:port/_cat/thread_pool/bulk?v&h=node_name,name,active,queue,rejected,c'
查詢主Master實(shí)例
curl -XGET --tlsv1.2 --negotiate -k -u : 'https://ip:port/_cat/master/?v'
查詢每個(gè)實(shí)例上的分片個(gè)數(shù),用于判斷分片是否均勻
curl -XGET --tlsv1.2 --negotiate -k -u : 'https://ip:port/_cat/allocation?v'
查詢_cat接口支持的所有的命令列表
curl -XGET --tlsv1.2 --negotiate -k -u : 'https://ip:port/_cat/'
查看分片未分配的原因
curl -XGET --tlsv1.2?--negotiate -k -u : "https://127.0.0.1:24100/_cat/shards?v&h=index,shard,prirep,state,unassigned.reason"?
?
?
_nodes命令???
查詢指定ES實(shí)例的jvm參數(shù):
curl -XGET –tlsv1.2 –negotiate -k -u : 'https://ip:port/_nodes/EsNode1*/stats/jvm?pretty'
curl -XGET –tlsv1.2 –negotiate -k -u : 'https://ip:port/_nodes/EsNode1@12.40.16.156/stats/jvm?pretty'
?
?
索引操作???
關(guān)閉索引
curl -XPOST --tlsv1.2 --negotiate -k -u : 'https://ip:port/my_index/_close?pretty'
打開(kāi)索引
curl -XPOST --tlsv1.2? --negotiate -k -u : 'https://ip:port/my_index/_open?pretty'
刪除索引,命令最后為索引名稱,只有該索引的創(chuàng)建用戶才可以刪除索引
curl -XDELETE?–tlsv1.2?–negotiate -k -u : 'https://ip:port/test_huawei'
查詢索引mapping和settings
curl -XPOST--tlsv1.2? --negotiate -k -u : 'https://ip:port/my_index_name?pretty'
查詢索引settings
curl -XPOST--tlsv1.2? --negotiate -k -u : 'https://ip:port/my_index_name/_settings?pretty'
修改索引刷新時(shí)間:
curl -XPUT --negotiate -k -u : 'https://ip:port/my_index/_settings?pretty' -H 'Content-Type: application/json' -d'{"refresh_interval" : "60s"}'
修改translog文件保留時(shí)長(zhǎng),默認(rèn)為12小時(shí)
curl -XPUT --negotiate -k -u : 'https://ip:port/my_index/_settings?pretty' -H 'Content-Type: application/json' -d'{"index.translog.retention.age" : "30m"}'
設(shè)置索引副本:
curl -XPUT --negotiate -k -u : 'https://ip:port/my_index/_settings?pretty' -H 'Content-Type: application/json' -d'{"number_of_replicas" : 1}'
強(qiáng)制flush
curl -XPOST --negotiate --tlsv1.2 -k -u :? 'https://ip:port/myindex/_flush'
強(qiáng)制refresh
curl -XPOST --negotiate --tlsv1.2 -k -u :? 'https://ip:port/myindex/_refresh'
強(qiáng)制執(zhí)行段合并
curl -XPOST --tlsv1.2 --negotiate -k -v -u : 'https://ip:httpport/myindex-001/_forcemerge?only_expunge_deletes=false&max_num_segments=1&flush=true&pretty'
?
配置控制段合并的refresh、merge線程數(shù)等
curl -XPUT? --tlsv1.2? --negotiate -k -u : "https://ip:port/my_index/_settings?pretty" -H 'Content-Type: application/json' -d'
{
"refresh_interval": "360s",
"merge":{
"scheduler":{
"max_merge_count" : "100",
"max_thread_count" : "1"
},
"policy":{
"segments_per_tier" : "100",
"floor_segment" : "1m",
"max_merged_segment" : "2g"
}
}
}'
設(shè)置索引的刷新時(shí)間和translog配置參數(shù)
注意:設(shè)置translog參數(shù),必須先關(guān)閉索引,設(shè)置完成后再打開(kāi)
*代表設(shè)置所有索引,如果要設(shè)置具體某個(gè)索引,可以將*替換為具體的索引名稱
curl -XPUT --tlsv1.2 --negotiate -k -v -u : "https://ip:httpport/*/_settings" -H 'Content-Type: application/json' -d'
{
"index": {
"refresh_interval" : "60s",
"translog": {
"flush_threshold_size": "1GB",
"sync_interval": "120s",
"durability": "async"
}
}
}'
?
手動(dòng)分片遷移操作
curl -XPOST?--tlsv1.2 --negotiate -k -v -u :??'https://ip:httpport/_cluster/reroute?pretty' -H 'Content-Type:application/json' -d '{
"commands" : [{
"move" : {
"index" : "info-test", "shard" : 3,
"from_node" : "EsNode3@189.39.172.103",
"to_node" : "EsNode2@189.39.172.103"
}
}]
}'
?
限制每個(gè)索引在每個(gè)實(shí)例上的分片個(gè)數(shù)
curl -XPUT?--tlsv1.2 --negotiate -k -v -u :?'https://http:httpport/myindex/_settings?pretty' -H 'Content-Type:application/json' -d '{"index.routing.allocation.total_shards_per_node":"2"}'
?
Shrink操作
1、目前集群默認(rèn)設(shè)置的是同一臺(tái)主機(jī)不能存放同一主副本分片,需先在后臺(tái)關(guān)閉該設(shè)置。防止分片自動(dòng)均衡,關(guān)閉分片分配。
curl -XPUT 'http://127.0.0.1:24100/_cluster/settings?pretty'-H 'Content-Type:application/json' -d '{"transient":{"cluster.routing.allocation.same_shard.host":false,"cluster.routing.allocation.enable":"none"}}'
2、將索引標(biāo)記為只讀,且所有的分片副本都遷移到實(shí)例名為EsNode1@IP的實(shí)例上。注意:“所有的分片副本”不指定索引的全部分片,無(wú)論主分片還是副本分片,任意一個(gè)就行。
curl -XPUT?"http://127.0.0.1:24100/jjj.pm_20190224/_settings" -H 'Content-Type:?application/json' -d'{
"settings": {???
"index.routing.allocation.require._name": "EsNode1@IP",
"index.blocks.write": true
? }
}'
3、執(zhí)行完上述命令之后,分片開(kāi)始遷移,執(zhí)行下列命令,查看分片是否遷移完成。
curl –XGET?http://127.0.0.1:24100/_cat/shards?v?| grep jjj.pm_20190224
4、分片轉(zhuǎn)移完成之后,查看集群是否green。
curl -XGET http://127.0.0.1:24100/_cluster/health?pretty
5、等待分片遷移完成之后,集群green后,我們就可以執(zhí)行Shrink操作了。
curl -XPOST "http://127.0.0.1:24100/jjj.pm_20190224/_shrink/ jjj.pm_20190224_new" -H 'Content-Type: application/json' -d'{
"settings": {
"index.number_of_replicas": 1,
"index.number_of_shards": 41,
"index.codec": "best_compression"
}
}'
以上代碼將創(chuàng)建含有一個(gè)41個(gè)主分片和一個(gè)副本分片的目的索引jjj.pm_20190224_new。
6、刪除原來(lái)的索引
curl -XDELETE http://127.0.0.1:24100/jjj.pm_20190224?pretty
7、并為新建的索引設(shè)置別名,別名設(shè)置為原來(lái)索引名稱。
curl -XPOST 'http://127.0.0.1:24100/_aliases?pretty' -H 'Content-Type: application/json' -d' {
"actions":
[{"add":{"index": "jjj.pm_20190224_new","alias":"jjj.pm_20190224"}}]}'
8、查看集群狀態(tài),green之后,還原參數(shù)。
curl -XPUT 'http://127.0.0.1:24100/_cluster/settings?pretty'-H 'Content-Type:application/json' -d
'{"transient":{"cluster.routing.allocation.same_shard.host":true,"cluster.routing.allocation.enable":"all"}}'
?
?
_template操作???
查看模板
curl -XGET –tlsv1.2 –negotiate -k -u : "https://ip:port/_template/template_1?pretty"
設(shè)置/修改模板
curl -XPUT –tlsv1.2 –negotiate -k -u : "https://ip:port/_template/template_1" -H 'Content-Type: application/json' -d '{ "template" : "*", "order" : 0, "settings" : { "number_of_shards" : 1 }, "mappings" : { "type1" : { "_source" : { "enabled" : false } } } }'
?
SQL插件常用用法???
curl -XPOST?–tlsv1.2?–negotiate -k -u : 'https://ip:port/_sql?pretty' -H "Content-Type: application/json" ?-d 'SELECT * FROM test_index'
如上所示,三個(gè)地方需要注意:
1.????????SQL語(yǔ)句使用?”-XPOST”
2.????????Ip:port后需要跟?”_sql”
3.????????-d后直接跟SQL語(yǔ)句
全局查詢:curl -XPOST?–tlsv1.2?–negotiate -k -u : 'https://ip:port/_sql?pretty' -H "Content-Type: application/json"? -d 'SELECT * FROM test_index'
單關(guān)鍵字查詢:curl -XPOST?–tlsv1.2?–negotiate -k -u : 'https://ip:port/_sql?pretty' -H "Content-Type: application/json"? -d 'SELECT * FROM test_index where content="美國(guó)"'
多關(guān)鍵字查詢:
curl -XPOST?–tlsv1.2?–negotiate -k -u : 'https://ip:port/_sql?pretty' -H "Content-Type: application/json"? -d 'SELECT * FROM test_index where content="美國(guó)" and content="中國(guó)"'
curl -XPOST?–tlsv1.2?–negotiate -k -u : 'https://ip:port/_sql?pretty' -H "Content-Type: application/json"? -d 'SELECT * FROM test_index where content="美國(guó)" or content="中國(guó)"'
單字段排序:
curl -XPOST?–tlsv1.2?–negotiate -k -u : 'https://ip:port/_sql?pretty' -H "Content-Type: application/json"? -d 'SELECT * FROM test_index where content="美國(guó)" or content="中國(guó)" ORDER BY _score DESC'
多字段排序:
curl -XPOST?–tlsv1.2?–negotiate -k -u : 'https://ip:port/_sql?pretty' -H "Content-Type: application/json"? -d 'SELECT * FROM test_index where (content1="美國(guó)" or content1="中國(guó)") ORDER BY content2 ASC, _score DESC'
模糊查詢:
curl -XPOST?–tlsv1.2?–negotiate -k -u : 'https://ip:port/_sql?pretty' -H "Content-Type: application/json"? -d 'SELECT * FROM test_index where content1 like "喀*湖"'
限制輸出個(gè)數(shù):
curl -XPOST?–tlsv1.2?–negotiate -k -u : 'https://ip:port/_sql?pretty' -H "Content-Type: application/json"? -d 'SELECT * FROM test_index limit 2'?
?
解釋分片命令???
curl -XGET --negotiate -k -u : "https://127.0.0.1:24100/_cluster/allocation/explain?pretty" -d '{
"index": "indexname",
"shard": 17,
"primary": true
}'
?
bulk操作???
讀取文件夾下的文件,通過(guò)bulk寫(xiě)入:
for file_each in `ls`
do
curl -XPOST?–tlsv1.2 --negotiate -k -v -u : 'https://127.0.0.1:24100/_bulk?pretty' -H 'Content-Type:application/json' --data-binary @${file_each}
done
總結(jié)
以上是生活随笔為你收集整理的es常用curl命令的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: VS code 使用 Remote-SS
- 下一篇: centos安装 TA-Lib