Last active
August 29, 2017 06:49
-
-
Save Pindar/8915371 to your computer and use it in GitHub Desktop.
This file contains 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/sh | |
# COPY of http://pastebin.com/zC9HU2pU | |
# Do elasticsearch optimize on logstash previous day index | |
# if $1 = all then optimize all indicies | |
esindex="/opt/elasticsearch/data/elasticsearch/nodes/0/indices" | |
# Grab yesterday's values | |
D=`date +%d -d yesterday` | |
M=`date +%m -d yesterday` | |
Y=`date +%Y -d yesterday` | |
today="`date +%Y`.`date +%m`.`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