在对集群进行扩容或者替换节点的时候,不可避免会有移动分片的操作,可以使用如下的语句进行操作,首先要关闭自动reshard
cluster.routing.allocation.disable_allocation = false
然后可以使用move、cancel以及allocate进行分片的移动、取消分配以及重新分配没有分配的shard到指定节点。
curl -XPOST 'localhost:9200/_cluster/reroute' -d '{
"commands" : [ {
"move" :
{
"index" : "test", "shard" : 0,
"from_node" : "node1", "to_node" : "node2"
}
},
"cancel" :
{
"index" : "test", "shard" : 0, "node" : "node1"
}
},
{
"allocate" : {
"index" : "test", "shard" : 1, "node" : "node3"
}
}
]
}'
当然,推荐使用kopf插件ÿ