4

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?

3 Answers 3

8

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"
}
Sign up to request clarification or add additional context in comments.

Comments

4

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 ']}'

Comments

0

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" } }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.