Skip to content

Instantly share code, notes, and snippets.

@fdv
Created February 20, 2016 16:27
Show Gist options
  • Save fdv/ee58db6c3da3bd31939e to your computer and use it in GitHub Desktop.
Save fdv/ee58db6c3da3bd31939e to your computer and use it in GitHub Desktop.
Rolling optimize of an ElasticSearch cluster
#!/bin/sh
HOST=$1
CURL_BIN=$(which curl)
if [ -z "$HOST" ]; then
echo "Host is missing"
exit 1
fi
if [ -z "$CURL_BIN" ]; then
echo "Curl binary is missing"
exit 1
fi
while [ true ]; do
for indice in $(${CURL_BIN} -XGET http://${HOST}:9200/_cat/indices | sort -rk 6 | awk '{print $3}'); do
if [ ! -z "$indice" ]; then
echo "Processing indice ${indice}"
${CURL_BIN} -XPOST http://${HOST}:9200/${indice}/_optimize?max_num_segments=1
echo
fi
done
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment