Skip to content

Instantly share code, notes, and snippets.

@arledesma
Last active July 28, 2017 00:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arledesma/1a9efb0e7bb82639c7f6a562bedc41fe to your computer and use it in GitHub Desktop.
Save arledesma/1a9efb0e7bb82639c7f6a562bedc41fe to your computer and use it in GitHub Desktop.
ES scripts
#!/bin/bash
if [ -n "$1" ]; then index=$1; fi
if [ -n "$2" ]; then shard=$2; fi
if [ -n "$3" ]; then targetNode=$3; fi
curl -u es_admin:$ESPASS -sS -XPOST 'localhost:9200/_cluster/reroute' -d "{
\"commands\" : [ {
\"allocate\" : {
\"index\" : \"${index}\",
\"shard\" : ${shard},
\"node\" : \"${targetNode:-${recoveryNode}}\",
\"allow_primary\" : true
}
}
]
}"
#!/bin/bash
index=$1
shard=$2
node=$3
targetNode=$4
allocate=""
[ -z "${node}" ] && echo "Usage: $0 indexName shardNumber primaryNode" && exit 1
[ -n "${targetNode}" ] && allocate=", { \"allocate\": { \"index\": \"${index}\", \"shard\": ${shard}, \"node\": \"${targetNode}\", \"allow_primary\": true } }"
reroute="{\"commands\": [{ \"cancel\": { \"index\": \"${index}\", \"shard\": ${shard}, \"node\": \"${node}\", \"allow_primary\": true } }${allocate}]}"
curl -u es_admin:$ESPASS -s -XPOST localhost:9200/_cluster/reroute -d "${reroute}"
#!/bin/bash
curl -s -u es_admin:$ESPASS localhost:9200/_cluster/state/blocks?pretty | grep -B2 "index closed" | grep -v description | grep -v '"4"' | awk
-d\" -f2 | xargs -n1 -I{} echo curl -u es_admin:$ESPASS "http://localhost:9200/{}/_alias/*" -XDELETE | bash -x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment