Regular cleaning elasticsearch the index

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/m0_37886429/article/details/102662747

Requirements: log retention month, automatically indexing data 30 days prior to the deletion of elasticsearch

#!/bin/bash
DATE=`date -d "30 days ago" +%Y.%m.%d`
ip=`ifconfig eth0 | grep "inet" | awk '{print $2}'`
curl -s  -XGET "http://$ip:9200/_cat/indices?v"| grep $DATE | awk -F '[ ]+' '{print $3}' > /tmp/elk.log
for elk in `cat /tmp/elk.log`
do
   curl  -XDELETE  "http://$ip:9200/$elk"
done

Guess you like

Origin blog.csdn.net/m0_37886429/article/details/102662747