索引这种格式

 

 以下脚本加入crontab

#每天清理es数据
0 1 * * * /data/sh/rm_esindex.sh >> /data/logs/crontab/rm_esindex.log 

  

#!/bin/sh

ip='192.168.0.57'
port='9200'
day=`date -d "1 month ago" +%Y.%m.%d`
echo ""
echo `date`
indexname=`curl -XGET -s $ip:$port/_cat/indices|awk '{print $3}'`
if [ $? -ne 0 ];then
    echo "Connect $ip:$port error...."
else
    echo "Connect $ip:$port Sucess,loading index ..."
fi

for i in $indexname
do
   time=`echo $i|awk -F"-" '{print $NF}'|egrep "([0-9][0-9][0-9][0-9]).(0[1-9]|[1][0-2]).(0[1-9]|[1-2][0-9]|3[0-1])"`
   if [ -n "$time" ];then   #
        if [ "$time" = "$day" ];then
            echo "Delete $i"
            curl -XDELETE http://$ip:$port/$i
        fi
    fi
done