Purging old indexes from elasticsearch with logstash
Currently doing some work on logstash and found myself wanting to delete indexes over a certain age. The following PHP script gets the job done. I use php as my primary command line scripting language so use or port as interested. #!/usr/bin/php <?php date_default_timezone_set(“America/Chicago”); $index_name = “logstash-“; $purge_age = 300; $elastic = “http://elastic.domain.com:9200”; $data = file_get_contents(“${elastic}/_cat/indices/${index_name}*”); foreach(split(“\n”, $data) as $line) { $split = preg_split(“/\s+/”, $line); if(count($split) > 1) { $date = preg_replace(“/${index_name}|\./”, “”, $split[2]); $split[] = floor((time() – strtotime($date)) /…