elasticsearch的索引自动清理及自定义清理

查询索引:

curl -XGET 'http://127.0.0.1:9200/_cat/indices/?v'

 

 

二、api删除

[root@elk sh]# curl -XDELETE http://localhost:9200/filebeat-6.0.0-2018.03.07
{"acknowledged":true}

 

三、脚本加api删除(推荐)

#!/bin/bash

#指定日期(2周前)
DATA=`date -d "2 weeks ago" +%Y.%m.%d`

echo $DATA

#当前日期
time=`date`

#删除2周前的日志
curl -XDELETE http://localhost:9200/*-${DATA}

if [ $? -eq 0 ];then
echo $time"-->del $DATA log success.." >> /tmp/es-index-clear.log
else
echo $time"-->del $DATA log fail.." >> /tmp/es-index-clear.log
fi

 

四、添加到任务计划

crontab -e

10 1 * * * sh /data/sh/es-index-clear.sh > /dev/null 2>&1

 

posted @ 2018-03-19 17:57  Oops!#  阅读(413)  评论(0编辑  收藏  举报