AXE Labs
AXE Labs

Reputation: 4561

How to move all elasticsearch shards from one node to another?

In ElasticSearch 2.X you can move shards around using reroute:

https://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-reroute.html#cluster-reroute

Other than specifying a move for each shard, is there an easy way to move all off them from one node to another?

Upvotes: 4

Views: 13592

Answers (3)

Farhad Kazemi
Farhad Kazemi

Reputation: 21

I found out that its better to use exclude api on your node's IP

PUT _cluster/settings { "transient" : {._ip "cluster.routing.allocation.exclude._ip" : "192.168.10.10" } }

Upvotes: 0

bittusarkar
bittusarkar

Reputation: 6357

Rerouting will not ensure the shards remain in the new node. Elasticsearch may try to balance things out and move some shards back to the original node. If you want to pin the shards to the new node, you need to use Shard Allocation Filtering.

If you want to move all shards of index index1 to node node1, then the command to execute is:

PUT index1/_settings
{
  "index.routing.allocation.include._name": "node1"
}

Upvotes: 8

AXE Labs
AXE Labs

Reputation: 4561

I've not found a move "all" option yet, but thanks to awk and the ES _cat API, I can generate the needed JSON for moving all shards from node1 to node2:

#!/bin/bash

OLD=node1
NEW=node2

SHARDS=`
curl -s -XGET "https://my.elasticsearch.cluster/_cat/shards/" | awk -v NEW=$NEW -v OLD=$OLD '$8==OLD {
  print "      { \"move\": { \"index\": \""$1"\", \"shard\": "$2", \"from_node\": \""OLD"\", \"to_node\": \""NEW"\" }},"
}'|sed '$ s/.$//'
`
echo '{"commands": ['
echo $SHARDS
echo ']}'

Upvotes: 4

Related Questions