(1)查询分片信息
curl http://127.0.0.1:9201/_cat/shards?pretty
curl http://127.0.0.1:9201/_cat/shards?pretty | grep UNASSIGNED
(2)查询分片状态unassigned的原因
curl -XGET http://127.0.0.1:9201/_cluster/allocation/explain?pretty
(3)重新分配分片
curl -XPOST http://127.0.0.1:9201/_cluster/reroute?retry_failed
(4)将一个陈旧的分片分配为主分片
curl -H "Content-Type:application/json" -XPOST http://127.0.0.1:9201/_cluster/reroute -d
'{
"commands": [
{
"allocate_stale_primary": {
"index": "xxx",
"shard": x,
"node": "xxx",
"accept_data_loss": true
}
}
]
}'
或者,将一个空分片分配为主分片
curl -H "Content-Type:application/json" -XPOST http://127.0.0.1:9201/_cluster/reroute -d
'{
"commands": [
{
"allocate_empty_primary": {
"index": "xxx",
"shard": x,
"node": "xxx",
"accept_data_loss": true
}
}
]
}'