Skip to content

Instantly share code, notes, and snippets.

@zealot128
Last active November 23, 2021 14:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zealot128/8b3e952a71be77bfa6a7f551b6854814 to your computer and use it in GitHub Desktop.
Save zealot128/8b3e952a71be77bfa6a7f551b6854814 to your computer and use it in GitHub Desktop.
Elasticsearch: migrate ALL shards from a master node to other nodes (e.g. mark all shards to move to other node before shutting down)
#!/bin/bash
# cluster
server="10.10.10.153:9200"
# new master node name
target="node123"
# fetch all index names
indices=`curl $server/_cat/indices?h=index`
# if only one node should be left, set to 0 to change settings too
number_of_replicas=0
for index in $indices
do
echo
echo "Moving $index..."
curl -XPUT $server/$index/_settings -H 'Content-Type: application/json' -d '{ "index.routing.allocation.include._name": "es.portal02.pludoni.com", "index.number_of_replicas": $number_of_replicas}'
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment