Skip to content

Instantly share code, notes, and snippets.

@jkordish
Last active December 29, 2016 11:20
Show Gist options
  • Save jkordish/0148096c7800c50925c0 to your computer and use it in GitHub Desktop.
Save jkordish/0148096c7800c50925c0 to your computer and use it in GitHub Desktop.
assigned all the unassigned shards quickly.
#!/bin/bash -e
for index in $(curl -sXGET http://localhost:9200/_cat/shards | grep UNASSIGNED | awk '{print $1}' | uniq); do
i=1
for shard in $(curl -XGET http://localhost:9200/_cat/shards?index=$index | grep UNASSIGNED | awk '{print $2}'); do
echo "$shard on $index going on datanode$i"
curl -sXPOST 'localhost:9200/_cluster/reroute' -d '{
"commands" : [ {
"allocate" : {
"index" : "'$index'",
"shard" : '$shard',
"node" : "datanode'$i'",
"allow_primary" : true
}
}
]
}' &> /dev/null
sleep 5
i=$((i + 1))
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment