elasticsearch可以通过reroute api来手动进行索引分片的分配.经常用来处理 unassigned shards的问题。
在ES2.x的reroute命令如下:
curl -XPOST 'localhost:9200/_cluster/reroute' -d '{
"commands" : [ {
"move" :
{
"index" : "test", "shard" : 0,
"from_node" : "node1", "to_node" : "node2"
}
},
{
"allocate" : {
"index" : "test", "shard" : 1, "node" : "node3",
"allow_primary":true (表示接受主分片数据丢失)
}
}
]
}'
ES5.x升级之后,已经把主分片的恢复和副本的恢复分开了
curl -XPOST 'localhost:9200/_cluster/reroute' -d '{
"commands" : [ {
"move" :
{
"index" : "test", "shard" : 0,
"from_node" : "node1", "to_node" : "node2"
}
},
{
"allocate_replica" : {
"index" : "test", "shard" : 1, "node" : "node3"
}
},
{
"allocate_empty_primary": {
"index" : "test", "shard" : 1, "node" : "node3",
"accept_data_loss":true (接受数据丢失)
}
}
]
}'
主分片的恢复用allocate_empty_primary,而副本的恢复用allocate_replica