#!/bin/bash
source /etc/profile
delete_indices(){
check_day=`date -d '-30 days' '+%F'`
index_day=$1
check_day_timestamp=`date -d "$check_day" +%s`
index_day_timestamp=`date -d "$index_day" +%s`
if [ ${index_day_timestamp} -lt ${check_day_timestamp} ];then
format_date=`echo $1 | sed 's/-/\./g'`
curl -XDELETE http://10.78.1.184:9200/*$format_date
fi
}
curl -XGET http://10.78.1.184:9200/_cat/indices | awk -F" " '{print $3}' | awk -F"-" '{print $NF}' | egrep "[0-9]*\.[0-9]*\.[0-9]*" | sort | uniq | sed 's/\./-/g' | while read LINE
do
delete_indices $LINE
done
转载出处https://blog.51cto.com/liuzhengwei521/2300163