You've successfully subscribed to Nuvotex Blog
Great! Next, complete checkout for full access to Nuvotex Blog
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.
Success! Your billing info is updated.
Billing info update failed.

Moving an elasticsearch index to another node

Lorenz Maier
Lorenz Maier

When hosting a multinode elasticsearch cluster, you might run in some state where indices are not equally balanced across your nodes, until one of them starts crying about high disk usage while other nodes are barely occupied - exactly this happened in one of our customers environment.

In order to get the affected node happy again, we've released some of the used disk space by moving old indicies to a different node inside the cluster. This is a quick guide on how to perform a such index migration.

With the use of the elastic console you can simply take a look at which node your indices are currently stored on and which of them is least used:

# get all indices sorted by node
GET _cat/shards?v=true&h=node,index&s=node&index=<YourIndex>-*

Again take a look at our indices, but this time sort them by name:

# get all indices sorted by index
GET _cat/shards?v=true&h=node,index&s=index&index=<YourIndex>-*

We simply grep the full name of the oldest index, which is currently stored on our affected node. In the next step we use the reroute API to migrate our selected index:

# move index to a different node
POST _cluster/reroute
{
  "commands": [
    {
      "move": {
        "index": "<YourIndexFullName>", "shard": 0,
        "from_node": "<YourSourceNode>", "to_node": "<YourTargetNode>"
      }
    }
  ]
}

Within the response you should see the acknowledged state. To check the migration process of your index execute:

# check migration progress
GET _cat/recovery/<YourIndexFullName>?format=json&h=index,shard,time,type,stage,source_node,target_node,bytes_percent

Simply repeat these steps until your indices are equally balanced across your nodes.
That's all it takes!

Database