Skip to content

Instantly share code, notes, and snippets.

@signalnine
Last active April 23, 2024 00:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save signalnine/37344a4b0f78af7d1c32 to your computer and use it in GitHub Desktop.
Save signalnine/37344a4b0f78af7d1c32 to your computer and use it in GitHub Desktop.
fix unallocated shards on ElasticSearch
NODE="hostname.you.com"
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' -d '{
"commands": [
{
"allocate": {
"index": "'$INDEX'",
"shard": '$SHARD',
"node": "'$NODE'",
"allow_primary": true
}
}
]
}'
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment