您的位置:首页 > 其它

Elasticsearch索引删除

2020-02-02 02:22 525 查看
#!/bin/bash
#通过任务计划自动删除es中30天以前的索引,以释放空间
ES_HOST='127.0.0.1';
ES_PORT=9200;
HTTP_PREFIX=http://${ES_HOST}:${ES_PORT}/

source /etc/profile
#定义删除30天以前的函数
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`
#当索引的时间戳值小于当前日期30天前的时间戳时,删除此索引
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_PREFIX}/_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://www.cnblogs.com/one-villager/p/10283183.html

  • 点赞
  • 收藏
  • 分享
  • 文章举报
baidu1966 发布了0 篇原创文章 · 获赞 0 · 访问量 360 私信 关注
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: