elasticsearch 常用命令
查看集群狀態:
curl -XGET 'http://localhost:9200/_cluster/health?pretty'查看所有節點狀態:
curl -XGET -s "http://192.168.1.102:9200/_cat/nodes" curl -XGET "http:192.168.1.102:9200/_node/stats/process"查看集群在recovery的index
GET */_recovery?active_only=true當集群分片分配失敗后,執行:
POST _cluster/reroute?retry_failed=true修改分片分配:
curl -XPUT 'http://192.168.1.101:9200/_cluster/settings' -H 'Content-Type: application/json' -d '{"transient":{"cluster.routing.allocation.enable": "none"}}'Disable shard allocation.
When you shut down a node, the allocation process waits for index.unassigned.node_left.delayed_timeout (by default, one minute) before starting to replicate the shards on that node to other nodes in the cluster, which can involve a lot of I/O. Since the node is shortly going to be restarted, this I/O is unnecessary. You can avoid racing the clock by disabling allocation of replicas before shutting down the node:?
當重啟節點時,移動分片會產生大量IO,這是沒必要的。往往在重啟節點的時候,將這個參數改為primaries。
可以是persistent 持久性的(重啟后依舊有效),也可以是 transient 臨時性的(完全重啟集群后失效)。
Allocation和Rebalancing的區別
Shard allocation is about taking unassigned shard copies and finding each of them a node to inhabit.
Rebalancing is about taking assigned shard copies and moving them to different nodes to even out the distribution of shards.
shard分配是指獲取未分配的shard副本,并找到它們中的每一個要駐留的節點。
重新平衡是指獲取分配的碎片副本并將其移動到不同的節點,以平衡碎片的分布。
cluster.routing.allocation.cluster_concurrent_rebalance
允許同時多少分片平衡數據,默認值為2,當集群狀態為green時,當一個節點加入進來,會執行此操作。
cluster.routing.allocation.node_concurrent_recoveries
從yellow到green的過程中,允許多少個分片平衡
創建index:
curl -XPUT 'http://192.168.1.101:9200/mobile_area' -H 'Content-Type: application/json' -d '"mappings":{"type":{"properties":{"name":{"type": "keyword"},"age":{"type": "keyword"}}}} 'bulk命令
curl -X POST "localhost:9200/_bulk" -H 'Content-Type: application/json' -d' { "index" : { "_index" : "test", "_id" : "1" } } { "field1" : "value1" } { "delete" : { "_index" : "test", "_id" : "2" } } { "create" : { "_index" : "test", "_id" : "3" } } { "field1" : "value3" } { "update" : {"_id" : "1", "_index" : "test"} } { "doc" : {"field2" : "value2"} } ' curl -X POST "http://192.168.159.128:9200/index_name/_index_type/_bulk" -H 'Content-type: application/json' --data-binary @file_name文件內容:
{"index":{}} {"name": "tom", "age": "12"} {"index":{}} {"name": "jerry", "age": "15"}?使用kibana進行bulk:
POST bzhan/type/_bulk { "index" : {}} {"name": "jack", "age": "12"} { "index" : {}} {"name": "rose", "age": "23"}修改副本數量
PUT _settings {"number_of_replicas": 3 }查看索引列表
curl -XGET 'http://192.168.171.39:9200/_cat/indices?v'默認情況下,會把所有的列都顯示出來:
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size如果只想要列名:
curl -XGET 'http://192.168.171.39:9200/_cat/indices?v&h=index'這樣就只把列名獲取出來了。
總結
以上是生活随笔為你收集整理的elasticsearch 常用命令的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Jena增删改查java API
- 下一篇: awk 处理json