Skip to content

Instantly share code, notes, and snippets.

@lgaggini
Created March 13, 2018 07:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lgaggini/08dff867af926094f2d47cd26ae044b4 to your computer and use it in GitHub Desktop.
Save lgaggini/08dff867af926094f2d47cd26ae044b4 to your computer and use it in GitHub Desktop.
Simple script to force reallocation of unassigned primary shard
HOST={{ some_master_hostname/ip address }}
PORT=9200
TO_NODE="{{ destination_node }}"
curl "http://$HOST:$PORT/_cat/shards" | grep UNAS | awk '{print $1" "$2}' | while read var_index var_shard; do
curl -XPOST "http://$HOST:$PORT/_cluster/reroute?pretty" -H 'Content-Type: application/json' -d "
{
\"commands\" : [
{
\"allocate_stale_primary\":
{
\"index\" : \"$var_index\",
\"shard\" : \"$var_shard\",
\"node\" : \"$TO_NODE\",
\"accept_data_loss\": true
}
}
]
}";
sleep 5;
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment