Skip to content

Instantly share code, notes, and snippets.

@fdv
Last active August 27, 2016 12:03
Show Gist options
  • Save fdv/a4cf10c2c3556f3cc5f2245699a8bb1b to your computer and use it in GitHub Desktop.
Save fdv/a4cf10c2c3556f3cc5f2245699a8bb1b to your computer and use it in GitHub Desktop.
# Mass index deletion with pattern
for index in $(curl -XGET esmaster:9200/_cat/indices | grep pattern | awk '{print $3}'); do curl -XDELETE esmaster:9200/$index?master_timeout=120s; done
# Mass optimize, indexes with the most deleted docs first
for indice in $(CURL -XGET esmaster:9200/_cat/indices | sort -rk 7 | awk '{print $3}'); do curl -XPOST http://esmaster:9200/${indice}/_optimize?max_num_segments=1; done
# Restart half a cluster using rack awareness
curl -XPUT 'host:9200/_cluster/settings' -d '{ "transient" : { "cluster.routing.allocation.enable": "none" }}'; for host in $(curl -XGET esmaster:9200/_cat/nodeattrs?attr | grep rack_id | awk '{print $2}'); do ssh $host service elasticsearch restart; done; sleep60; curl -XPUT 'host:9200/_cluster/settings' -d '{ "transient" : { "cluster.routing.allocation.enable": "all }}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment