ES 常用命令彙總

一:_cat系列
_cat系列提供了一系列查詢elasticsearch集羣狀態的接口。你可以通過執行
curl -XGET localhost:9200/_cat
獲取所有_cat系列的操作

/_cat/allocation
/_cat/shards
/_cat/shards/{index}
/_cat/master
/_cat/nodes
/_cat/indices
/_cat/indices/{index}
/_cat/segments
/_cat/segments/{index}
/_cat/count
/_cat/count/{index}
/_cat/recovery
/_cat/recovery/{index}
/_cat/health
/_cat/pending_tasks
/_cat/aliases
/_cat/aliases/{alias}
/_cat/thread_pool
/_cat/plugins
/_cat/fielddata
/_cat/fielddata/{fields}

你也可以後面加一個v,讓輸出內容表格顯示錶頭,舉例

二:_cluster系列

1、查詢設置集羣狀態
curl -XGET localhost:9200/_cluster/health?pretty=true
pretty=true表示格式化輸出
level=indices 表示顯示索引狀態
level=shards 表示顯示分片信息
2、curl -XGET localhost:9200/_cluster/stats?pretty=true
顯示集羣系統信息,包括CPU JVM等等
3、curl -XGET localhost:9200/_cluster/state?pretty=true
集羣的詳細信息。包括節點、分片等。
3、curl -XGET localhost:9200/_cluster/pending_tasks?pretty=true
獲取集羣堆積的任務
3、修改集羣配置
舉例:

curl -XPUT localhost:9200/_cluster/settings -d ‘{
“persistent” : {
“discovery.zen.minimum_master_nodes” : 2
}
}’
transient 表示臨時的,persistent表示永久的
4、curl -XPOST ‘localhost:9200/_cluster/reroute’ -d ‘xxxxxx’
對shard的手動控制,參考http://zhaoyanblog.com/archives/687.html
5、關閉節點
關閉指定192.168.1.1節點
curl -XPOST ‘http://192.168.1.1:9200/_cluster/nodes/_local/_shutdown’
curl -XPOST ‘http://localhost:9200/_cluster/nodes/192.168.1.1/_shutdown’
關閉主節點
curl -XPOST ‘http://localhost:9200/_cluster/nodes/_master/_shutdown’
關閉整個集羣
$ curl -XPOST ‘http://localhost:9200/_shutdown?delay=10s’
$ curl -XPOST ‘http://localhost:9200/_cluster/nodes/_shutdown’
$ curl -XPOST ‘http://localhost:9200/_cluster/nodes/_all/_shutdown’
delay=10s表示延遲10秒關閉

三:_nodes系列
1、查詢節點的狀態
curl -XGET ‘http://localhost:9200/_nodes/stats?pretty=true’
curl -XGET ‘http://localhost:9200/_nodes/192.168.1.2/stats?pretty=true’
curl -XGET ‘http://localhost:9200/_nodes/process’
curl -XGET ‘http://localhost:9200/_nodes/_all/process’
curl -XGET ‘http://localhost:9200/_nodes/192.168.1.2,192.168.1.3/jvm,process’
curl -XGET ‘http://localhost:9200/_nodes/192.168.1.2,192.168.1.3/info/jvm,process’
curl -XGET ‘http://localhost:9200/_nodes/192.168.1.2,192.168.1.3/_all
curl -XGET ‘http://localhost:9200/_nodes/hot_threads

第四:索引操作
1、獲取索引
curl -XGET ‘http://localhost:9200/{index}/{type}/{id}’
2、索引數據
curl -XPOST ‘http://localhost:9200/{index}/{type}/{id}’ -d’{“a”:”avalue”,”b”:”bvalue”}’
3、刪除索引
curl -XDELETE ‘http://localhost:9200/{index}/{type}/{id}’
4、設置mapping

curl -XPUT http://localhost:9200/{index}/{type}/_mapping -d ‘{
“{type}” : {
“properties” : {
“date” : {
“type” : “long”
},
“name” : {
“type” : “string”,
“index” : “not_analyzed”
},
“status” : {
“type” : “integer”
},
“type” : {
“type” : “integer”
}
}
}
}’
5、獲取mapping
curl -XGET http://localhost:9200/{index}/{type}/_mapping
6、搜索

curl -XGET ‘http://localhost:9200/{index}/{type}/_search’ -d '{
“query” : {
“term” : { “user” : “kimchy” } //查所有 “match_all”: {}
},
“sort” : [{ “age” : {“order” : “asc”}},{ “name” : “desc” } ],
“from”:0,
“size”:100
}
curl -XGET ‘http://localhost:9200/{index}/{type}/_search’ -d '{
“filter”: {“and”:{“filters”:[{“term”:{“age”:“123”}},{“term”:{“name”:“張三”}}]},
“sort” : [{ “age” : {“order” : “asc”}},{ “name” : “desc” } ],
“from”:0,
“size”:100
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章