Created
September 25, 2015 01:28
-
-
Save sh4t/597a029ebaedb672576f to your computer and use it in GitHub Desktop.
move replica, unassigned shards that match specific shard number to another node
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I use the Zp == Zp (adding additional character) as a simple safety net a bit.. just my caution.