Created
December 3, 2014 07:12
-
-
Save mrobee/ce2751489d998e64e12f to your computer and use it in GitHub Desktop.
Reroute Elasticsearch Unassigned Shards
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
#!/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