Skip to content

Instantly share code, notes, and snippets.

@pedroagabreu
Created April 17, 2014 19:53
Show Gist options
  • Save pedroagabreu/11007796 to your computer and use it in GitHub Desktop.
Save pedroagabreu/11007796 to your computer and use it in GitHub Desktop.
Elasticsearch cleanup, courtesy of http://thejmlcontinuum.blogspot.com.
#!/bin/bash
# delete one day
# curl -s -XDELETE 'http://127.0.0.1:9200/logstash-2014.02.28'
# delete from crontab
# DATETODELETE=`date +%Y.%m.%d -d '7 days ago'`
# curl -s -XDELETE http://127.0.0.1:9200/logstash-${DATETODELETE}
# delete by space
DESIRED=250000000
AVAIL=`df /data|grep -v Filesystem|awk '{print $4}'`
if [ $AVAIL -lt $DESIRED ]
then
curl -s -XDELETE 127.0.0.1:9200/`curl -s 127.0.0.1:9200/_stats?pretty|grep logstash|sort|awk -F'"' '{ print $2 }'|head -n1`
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment