Skip to content

Instantly share code, notes, and snippets.

@hivefans
Last active March 17, 2020 02:03
Show Gist options
  • Select an option

  • Save hivefans/eeb84f3c91f946f0e83d4f9d34d97476 to your computer and use it in GitHub Desktop.

Select an option

Save hivefans/eeb84f3c91f946f0e83d4f9d34d97476 to your computer and use it in GitHub Desktop.
|-|{"files":{"shardallocate.sh":{"env":"plain"}},"tag":"bigdata"}
function reroute() {
curl -XPOST 'localhost:9200/_cluster/reroute?pretty' -d '{
"commands" : [ {
"allocate" : {
"index" : "'$1'",
"shard" : '$2'
"allow_primary" : true,
"node" : "<node>"
}
}
]
}' > /dev/null
sleep 1
}
curl -s localhost:9200/_cluster/state?pretty | awk '
BEGIN {more=1}
{if (/"UNASSIGNED"/) unassigned=1}
{if (/"routing_nodes"/) more=0}
{if (unassigned && /"shard"/) shard=$3}
{if (more && unassigned && /"index"/) {print "reroute",$3, shard; unassigned=false}}
' > runit
source runit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment