Skip to content

Instantly share code, notes, and snippets.

@kcrayon
Forked from tolland/logstash_daily.sh
Created September 25, 2012 18:22
Show Gist options
  • Save kcrayon/3783553 to your computer and use it in GitHub Desktop.
Save kcrayon/3783553 to your computer and use it in GitHub Desktop.
Quick cron.daily script for stock Logstash/ES installation
#!/bin/sh
# Do elasticsearch optimize on logstash previous day index
# if $1 = all then optimize all indicies
esindex="/opt/elasticsearch/data/elasticsearch/nodes/0/indices"
today=`date +%Y.%m.%d`
yesterday=`date -d yesterday +%Y.%m.%d`
# If $1 = all
if [ "x$1" = "xall" ]
then
# Loop through all ES indicies except today
for index in `ls $esindex | grep -v "$today"`
do
# Run through all the indicies and optimize them
echo "Optimizing $index"
curl -XPOST "http://localhost:9200/$index/_optimize?max_num_segments=2"
done
else
echo "Optimizing index logstash-$yesterday"
curl -XPOST "http://localhost:9200/logstash-$yesterday/_optimize?max_num_segments=2"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment