Created
August 17, 2017 19:38
-
-
Save ricardofalasca/2ef4ca2c612f616ca3678d916fb4eb67 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
if [ "$1" == "" ] || [ "$2" == ""] ; | |
then | |
echo "\nUse: $0 <es_host> <node_name> [optional] <index_name>\n" | |
exit; | |
fi | |
for index_shards in $(curl -s -XGET http://$1:9200/_cat/shards | grep UNASSIGNED | awk '{print $1"|"$2;}'); | |
do | |
index=$(echo $index_shards | cut -d'|' -f 1) | |
shard=$(echo $index_shards | cut -d'|' -f 2) | |
echo "\n - Rerouting $1->$index[$shard]" | |
curl -XPOST "$1:9200/_cluster/reroute" -d "{ | |
\"commands\" : [ { | |
\"allocate\" : { | |
\"index\" : \"$index\", | |
\"shard\" : \"$shard\", | |
\"node\" : \"$2\", | |
\"allow_primary\" : true | |
} | |
} | |
] | |
}" | |
sleep 2 | |
echo " ... done.\n" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment