定期清理elasticsearch中的索引

需求: 日誌保留一個月,到時自動將30天前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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章