Tips and Tricks: Manually Allocate Elasticsearch Shards

Friday, Sep 24, 2021 14:00 · 167 words · 1 minute read

Tips and Tricks

  1. K8S Context Commands
  2. Manually Allocate Elasticsearch Shards
  3. Switch K8S Namespace
  4. Tail Logs in K8S

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.

comments powered by Disqus

Buy Me A Coffee