Last active
January 5, 2017 08:45
-
-
Save kszarek/e80ff3d1bbb10363feb2 to your computer and use it in GitHub Desktop.
Allocate unassiged shard in ES
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 | |
if [[ $# -ne 1 ]] | |
then | |
echo "Allocate an unassigned shard to a node." | |
echo | |
echo "$0 destination_node_name" | |
exit 1 | |
fi | |
# The allow_primary parameter will force a new empty primary shard to be allocated without any data. | |
# If a node which has a copy of the original shard (including data) rejoins the cluster later on, | |
# that data will be deleted: the old shard copy will be replaced by the new live shard copy. | |
allow_primary=false | |
export NODE=$1 | |
export 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}')) | |
curl -XPOST 'localhost:9200/_cluster/reroute' -d '{ | |
"commands": [ | |
{ | |
"allocate": { | |
"index": "'$INDEX'", | |
"shard": '$SHARD', | |
"node": "'$NODE'", | |
"allow_primary": "'$allow_primary'" | |
} | |
} | |
] | |
}' | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment