Skip to content

Instantly share code, notes, and snippets.

@mrobee
Created December 3, 2014 07:12
Show Gist options
  • Save mrobee/ce2751489d998e64e12f to your computer and use it in GitHub Desktop.
Save mrobee/ce2751489d998e64e12f to your computer and use it in GitHub Desktop.
Reroute Elasticsearch Unassigned Shards
#!/usr/bin/sh
host=$1
port=$2
unass=`curl -s -XGET http://$host:$port/_cat/shards | grep UNASSIGN | awk '{print $1}'`
for i in $unass; do
sors=`curl -s -XGET http://$host:$port/_cat/shards/$i | awk '{print $8}' | grep -i '\w' | sort | uniq -c | grep -i '2 ' | awk '{print $2}' | head -n 1`
dest=`curl -s -XGET http://$host:$port/_cat/shards/$i | awk '{print $8}' | grep -i '\w' | sort | uniq -c | grep -i '1 ' | awk '{print $2}'`
curl -XPOST http://$host:$port/_cluster/reroute -d "
{
\"commands\": [{
\"move\": {
\"index\": \"$i\",
\"shard\": 0,
\"from_node\": \"$sors\",
\"to_node\": \"$dest\" }}]}"
sleep 10
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment