查看集群状态:
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:
curl -X PUT "localhost:9200/_cluster/settings" -H 'Content-Type: application/json' -d'
{
"persistent": {
"cluster.routing.allocation.enable": "none"
}
}
'
当重启节点时,移动分片会产生大量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'
这样就只把列名获取出来了。