ikuwow
4/20/2016 - 4:37 AM

full_reroute.sh

#!/bin/bash

# re-allocate shards of node "Wildboys" (ip=10.252.1.114)

variable=$(curl -X GET 10.252.1.114:9200/_cat/shards | grep UNASSIGNED | awk -v OFS=, '{print $1,$2,$3}')
for shard in $variable; do
    index=$(echo $shard | cut -d, -f1)
    snum=$(echo $shard | cut -d, -f2)
    pr=$(echo $shard | cut -d, -f3)
    echo
    echo $index
    echo $snum
    echo
    curl -X POST '10.252.1.114:9200/_cluster/reroute' -d "{
        \"commands\" : [ {
            \"allocate\" : {
                \"index\" : \"${index}\",
                \"shard\" : ${snum},
                \"node\" : \"Wildboys\",
                \"allow_primary\" : true
            }
        }]
    }"
    sleep 1
done