Skip to content

Instantly share code, notes, and snippets.

@sh4t
Created September 25, 2015 01:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sh4t/597a029ebaedb672576f to your computer and use it in GitHub Desktop.
Save sh4t/597a029ebaedb672576f to your computer and use it in GitHub Desktop.
move replica, unassigned shards that match specific shard number to another node
#!/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
@sh4t
Copy link
Author

sh4t commented Sep 25, 2015

I use the Zp == Zp (adding additional character) as a simple safety net a bit.. just my caution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment