> 其它学习 > Elasticsearch >

elasticsearch定时删除索引

删除索引的命令
 
curl -XDELETE http://192.168.207.73:9200/*-2019.07.25
curl -XDELETE http://192.168.207.73:9200/*-2019.07.*
 
es定时删除索引步骤:
 
Step1
vi /usr/sxy/es-index-clear.sh
内容如下:
 
LAST_DATA=date -d "-2 days" "+%Y.%m.%d"
curl -XDELETE http://192.168.207.73:9200/*-${LAST_DATA}
 
#删除三天前的索引
#建索引时格式为es-*-YYYY.MM.dd
(例如index => “es-%{+YYYY.MM.dd}” )
 
LAST_DATA=`date -d "-3 days" "+%Y.%m.%d"`
curl -XDELETE http://192.168.207.73:9200/*-${LAST_DATA}

 
Step2
chmod 777 es-index-clear.sh
 
Step3
#crontab -e
内容如下:
32 11 * * * /usr/sxy/es-index-clear.sh
(每天的11点32执行定时任务)
 
Step4
service crond restart(可以不执行)
 
Step5
tail -f /var/log/cron
 
出现下图,表明成功
 
出现如下结果,失败
 
 


(责任编辑:IT)