ES普通模式下基礎(chǔ)操作

查詢某臺機(jī)器的狀態(tài)

curl http://localhost:8200/_cluster/nodes/10.0.2.226?pretty

使用通配符查詢

curl http://localhost:8200/_cluster/nodes/10.0.2.2*?pretty

?獲取集群健康狀態(tài)

curl -XGET 'http://192.168.10.84:9200/_cluster/health?pretty'

獲取集群全局狀態(tài)

curl -XGET 'http://192.168.10.84:9200/_cluster/stats?pretty'

解釋集群分片

curl -XGET 'http://192.168.10.84:9200/_cluster/allocation/explain?pretty' -H 'Content-Type:application/json' -d '{"index""indexname","shard"number of shards,"primary"true}'

curl -XGET 'http://192.168.10.84:9200/_cluster/allocation/explain?pretty' -H 'Content-Type:application/json' -d '{"index""indexname","shard"number of shards,"primary"true}'
?查詢_cat接口支持的所有命令列表
curl -XGET 'http://192.168.10.84:9200/_cat/'
?查詢集群健康狀態(tài)
curl -XGET 'http://192.168.10.84:9200/_cat/health?v'

查詢索引列表【生產(chǎn)環(huán)境會有多個索引】

curl -XGET 'http://192.168.10.84:9200/_cat/indices?v'
?查詢集群實例列表
curl -XGET 'http://192.168.10.84:9200/_cat/nodes?v'
?查詢nodes接口的幫助信息
curl -XGET 'http://192.168.10.84:9200/_cat/nodes?help'
?查詢nodes指定參數(shù)列的值
curl -XGET 'http://192.168.10.84:9200/_cat/nodes?v&h=http,dt,du,dup,hm,hc,hp,fdm,fdc,fdp,cpu'
?查詢集群線程池使用情況
curl -XGET 'http://192.168.10.84:9200/_cat/thread_pool?v'
?查詢集群bulk線程數(shù)
curl -XGET 'http://192.168.10.84:9200/_cat/thread_pool/bulk?v'
curl -XGET 'http://192.168.10.84:9200/_cat/thread_pool/bulk?v&h=node_name,active,queue,rejected,c'

[zkx@node04 ~]$ curl -XGET 'http://192.168.10.84:9200/_cat/thread_pool/bulk?v'
node_name name active queue rejected
[zkx@node04 ~]$ curl -XGET 'http://192.168.10.84:9200/_cat/thread_pool/bulk?v&h=node_name,active,queue,rejected,c'
node_name active queue rejected c

?查詢主master實例
curl -XGET 'http://192.168.10.84:9200/_cat/master?v'

[zkx@node04 ~]$ curl -XGET 'http://192.168.10.84:9200/_cat/master?v'
id                     host          ip            node
6lVL28gETga0UcaL1Aki6g 192.168.10.86 192.168.10.86 node06

?查詢每個實例的分片個數(shù)
curl -XGET 'http://192.168.10.84:9200/_cat/allocation?v'

?查看分片未分配的原因
curl -XGET 'http://192.168.10.84:9200/_cat/shards?v&h=index,shard,prirep,state,ur'

[zkx@node04 ~]$ curl -XGET 'http://192.168.10.84:9200/_cat/shards?v&h=index,shard,prirep,state,ur'
index   shard prirep state   ur
.kibana 0     p      STARTED
.kibana 0     r      STARTED
index1  1     r      STARTED
index1  1     p      STARTED
index1  3     r      STARTED
index1  3     p      STARTED
index1  2     p      STARTED
index1  2     r      STARTED
index1  4     p      STARTED
index1  4     r      STARTED
index1  0     r      STARTED
index1  0     p      STARTED

_nodes命令
?查詢所有EsMaster實例的jvm參數(shù)
curl -XGET 'http://192.168.10.84:9200/_nodes/EsMaster*/stats/jvm?pretty'

?查詢指定EsMaster實例的jvm參數(shù)
curl -XGET 'http://192.168.10.84:9200/_nodes/EsMaster@ip/stats/jvm?pretty'
?查詢所有EsNode實例的jvm參數(shù)
curl -XGET 'http://192.168.10.84:9200/_nodes/EsNode*/stats/jvm?pretty'
?查詢指定EsNode1實例的jvm參數(shù)
curl -XGET 'http://192.168.10.84:9200/_nodes/EsNode1@ip/stats/jvm?pretty'
curl -XGET 'http://192.168.10.84:9200/_nodes/EsNode1@192.168.10.84/stats/jvm?pretty'
索引操作
?新建索引,并設(shè)置副本數(shù)
curl -XPUT 'http://192.168.10.84:9200/website?pretty' -H 'Content-Type: application/json' -d' {"settings" : {"number_of_shards" : 3,"number_of_replicas" : 1} }'

例如:curl -XPUT 'http://10.131.112.121:24100/website?pretty' -H 'Content-Type: application/json' -d' {"settings" : {"number_of_shards" : 3,"number_of_replicas" : 1} }'

?查詢指定索引mappings
curl -XGET 'http://192.168.10.84:9200/website/_mappings?pretty'
?查詢指定索引settings
curl -XGET 'http://192.168.10.84:9200/website/_settings?pretty'
?寫入數(shù)據(jù)
curl -XPOST 'http://192.168.10.84:9200/website/blog/123?pretty' -H 'Content-Type: application/json' -d' {"title": "My first blog entry", "text": "Just trying this out...","date": "2014/01/01"}'
?關(guān)閉索引
curl -XPOST 'http://192.168.10.84:9200/website/_close?pretty'
?打開索引
curl -XPOST 'http://192.168.10.84:9200/website/_open?pretty'
?刪除索引
curl -XDELETE 'http://192.168.10.84:9200/indexName?pretty'
?修改索引刷新時間
curl -XPUT 'http://192.168.10.84:9200/website/_settings?pretty' -H 'Content-Type: application/json' -d'{"refresh_interval" : "time (unit: seconds)"}'
?清理Elasticsearch查詢緩存
curl -XPOST 'http://192.168.10.84:9200/_cache/clear?pretty'
?設(shè)置索引副本
curl -XPUT 'http://192.168.10.84:9200/indexName/_settings?pretty' -H 'Content-Type: application/json' -d'{"number_of_replicas" : number of replicas}'
?執(zhí)行refresh,將內(nèi)存數(shù)據(jù)刷新到磁盤緩存
curl -XPOST 'http://192.168.10.84:9200/_refresh?pretty'
?執(zhí)行flush,將磁盤緩存刷新到文件系統(tǒng)
curl -XPOST 'http://192.168.10.84:9200/_flush?pretty'
?執(zhí)行synced flush,將磁盤緩存刷新到文件系統(tǒng),并生成相同的syncid
curl -XPOST 'http://192.168.10.84:9200/indexName/_flush/synced?pretty'
?執(zhí)行段合并
curl -XPOST 'http://192.168.10.84:9200/indexName/_forcemerge?only_expunge_deletes=false&max_num_segments=1&flush=true&pretty'
?設(shè)置索引在每個實例上的分片個數(shù)
curl -XPUT 'http://192.168.10.84:9200/indexName/_settings?pretty' -H 'Content-Type:application/json' -d '{"index.routing.allocation.total_shards_per_node":"number of shards"}'
?檢查文檔是否存在
curl -i -HEAD 'http://192.168.10.84:9200/indexName/type/indexID?pretty'
?查詢索引全部數(shù)據(jù)【OK】
curl -XGET 'http://192.168.10.84:9200/website/_search?pretty'
?查詢指定ID數(shù)據(jù)【OK】
curl -XGET 'http://192.168.10.84:9200/indexName/type/indexID?pretty'
?查詢文檔的一部分?jǐn)?shù)據(jù)
curl -XGET 'http://192.168.10.84:9200/indexName/type/indexID?_source=documentAttributeName1,documentAttribute2&pretty'
?刪除文檔
curl -XDELETE 'http://192.168.10.84:9200/indexName/type/indexID?pretty'

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容