Skip to content

Instantly share code, notes, and snippets.

@ricardofalasca
Created August 17, 2017 19:38
Show Gist options
  • Save ricardofalasca/2ef4ca2c612f616ca3678d916fb4eb67 to your computer and use it in GitHub Desktop.
Save ricardofalasca/2ef4ca2c612f616ca3678d916fb4eb67 to your computer and use it in GitHub Desktop.
#!/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