Tips and Tricks: Manually Allocate Elasticsearch Shards
Friday, Sep 24, 2021 14:00 · 167 words · 1 minute read
Tips and Tricks
Problem
In this blog post I will describe how to manually rebalance an Elasticsearch shards across its data nodes by reallocating them. Actually this is pretty simple operation thanks to the powerful Elasticsearch REST API.
Solution
The reroute command allows manual realocation of an individual ES shard from one node to another. Have in mind that if you have enabled the cluster.routing.rebalance.enable setting, the ES cluster will perform rebalancing as normal (to keep the balanced state), otherwise only the explicit realocations will be performed, and consequent allocations due to rebalancing.
POST _cluster/reroute
{
"commands": [
{
"move": {
"index": "jaeger-span-2021-09-24",
"shard": 0,
"from_node": "es-data-0",
"to_node": "es-data-2"
}
}
]
}
Example using curl
curl "http://<es-host>:<es-port>/_cluster/reroute" -H "Content-Type: application/json" -d '{
"commands": [
{
"move": {
"index": "jaeger-span-2021-09-24",
"shard": 0,
"from_node": "es-data-0",
"to_node": "es-data-2"
}
}
]
}'
More information about the reroute command can be found in the Elasticsearch documentation.