Skip to content

Instantly share code, notes, and snippets.

@sh4t
Created September 25, 2015 01:28
Show Gist options
  • Select an option

  • Save sh4t/597a029ebaedb672576f to your computer and use it in GitHub Desktop.

Select an option

Save sh4t/597a029ebaedb672576f to your computer and use it in GitHub Desktop.

Revisions

  1. sh4t created this gist Sep 25, 2015.
    38 changes: 38 additions & 0 deletions unassigned.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@
    #!/bin/bash
    # danger! danger!
    #

    IFS=$'\n'
    for line in $(curl -s 'localhost:9200/_cat/shards' | fgrep '0 r UNASSIGNED'); do
    #for line in $(curl -s 'localhost:9200/_cat/shards' | fgrep 'UNASSIGNED'); do
    INDEX=$(echo $line | (awk '{print $1}'))
    SHARD=$(echo $line | (awk '{print $2}'))
    SHARD_TYPE=$(echo $line | (awk '{print $3'}))

    curl -XPOST 'localhost:9200/_cluster/reroute' -d '{
    "commands": [
    {
    "allocate": {
    "index": "'$INDEX'",
    "shard": '$SHARD',
    "node": "data3-sjc1",
    "allow_primary": true
    }
    }
    ]
    }' >> ./data3.json

    # a way I can comment out above and then run
    # the loop with these conditions to see what is primary
    # versus what is replica
    #
    # if [ "Z${SHARD_TYPE}" == "Zr" ]
    # then
    # echo "${INDEX} ${SHARD} [replica]"
    # elif [ "Z${SHARD_TYPE}" == "Zp" ]
    # then
    # echo "${INDEX} ${SHARD} [primary]"
    # else
    # exit 99
    # fi
    done