Skip to content

Instantly share code, notes, and snippets.

@alexlovelltroy
Created December 18, 2014 20:33
Show Gist options
  • Save alexlovelltroy/5937eac8f1a21e8fec4c to your computer and use it in GitHub Desktop.
Save alexlovelltroy/5937eac8f1a21e8fec4c to your computer and use it in GitHub Desktop.
reallocate unassigned shards in elasticsearch
NODE="a hostname"
IFS=$'\n'
for line in $(curl -s 'localhost:9200/_cat/shards' | fgrep UNASSIGNED); do
INDEX=$(echo $line | (awk '{print $1}'))
SHARD=$(echo $line | (awk '{print $2}'))
curl -XPOST 'localhost:9200/_cluster/reroute?pretty' -d '{
"commands": [
{
"allocate": {
"index": "'$INDEX'",
"shard": '$SHARD',
"node": "'$NODE'",
"allow_primary": true
}
}
]
}'
done
@alexlovelltroy
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment