Skip to main content
Elasticsearch allocate unassigned shards
range=2
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}'))
number=$RANDOM
let "number %= ${range}"
curl -H 'Content-Type:application/json' -XPOST http://localhost:9200/_cluster/reroute? -d '{
"commands" : [ {
"allocate_empty_primary" :
{
"index" : '\"${INDEX}\"',
"shard" : '\"${SHARD}\"',
"node" : "tigger-1",
"accept_data_loss" : true
}
}
]
}'
done