Skip to content

Instantly share code, notes, and snippets.

@mastier
Created April 10, 2018 17:07
Show Gist options
  • Save mastier/7cb7e1b8e130bd0832fde1cda58a8823 to your computer and use it in GitHub Desktop.
Save mastier/7cb7e1b8e130bd0832fde1cda58a8823 to your computer and use it in GitHub Desktop.
reassign unassigned shards in elastic
#!/usr/bin/env bash
read -e -p 'Give cluster IP:' -i "$( hostname )" IP
read -e -p 'Give cluster node:' -i "$( hostname )" NODE
read -e -p 'any node suffix?:' -i '_es-01' SUFFIX
IFS=$'\n'
for line in $(curl -s "$IP:9200/_cat/shards" | fgrep UNASSIGNED); do
INDEX=$(echo $line | (awk '{print $1}'))
SHARD=$(echo $line | (awk '{print $2}'))
echo "Reassigning $SHARD $INDEX"
curl -XPOST "$IP:9200/_cluster/reroute" -d '{
"commands": [
{
"allocate": {
"index": "'$INDEX'",
"shard": '$SHARD',
"node": "'$NODE$SUFFIX'",
"allow_primary": true
}
}
]
}'
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment