使用curl命令操作elasticsearch
第一:_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,讓輸出內容表格顯示表頭,舉例
name component version type url Prometheus analysis-mmseg NA j Prometheus analysis-pinyin NA j Prometheus analysis-ik NA j Prometheus analysis-ik NA j Prometheus analysis-smartcn 2.1.0 j Prometheus segmentspy NA s /_plugin/segmentspy/ Prometheus head NA s /_plugin/head/ Prometheus bigdesk NA s /_plugin/bigdesk/ Xandu analysis-ik NA j Xandu analysis-pinyin NA j Xandu analysis-mmseg NA j Xandu analysis-smartcn 2.1.0 j Xandu head NA s /_plugin/head/ Xandu bigdesk NA s /_plugin/bigdesk/ Onyxx analysis-ik NA j Onyxx analysis-mmseg NA j Onyxx analysis-smartcn 2.1.0 j Onyxx analysis-pinyin NA j Onyxx head NA s /_plugin/head/ Onyxx bigdesk NA s /_plugin/bigdesk/
第二:_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 }
########################################



