微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

elasticsearch 删除index

单个删除

#!/bin/bash

> /home/xx/es_index_delete_list

curl -s --user elastic:passwd -XGET 'http://xxx:9200/_cat/indices/?v'|awk '{print $3}' > /home/xx/es_indexs
cat es_indexs |sort |awk -F'-2022' '{print $1}'|uniq -c > es_indexs1

cat es_indexs1 |while read line;do
b=`echo $line|awk '{print $1}'`;
c=`echo $line|awk '{print $2}'`;
if [[ "$b" -gt "10" ]];then
curl -s --user elastic:passwd -XGET 'http://xx:9200/_cat/indices/?v'|awk '{print $3}'|grep -E ^$c-*|sort |head -n 5 >> /home/xx/es_index_delete_list /dev/null 2>&1
fi
done > /dev/null 2>&1

es_index_list=`cat /home/xx/es_index_delete_list|tr '\n' ' '`

for del in $es_index_list;do
curl -s --user elastic:nfJi2U0Ql473tvxlnVUQ -XDELETE http://xxx:9200/$del >/dev/null 2>&1
done

日期删

#!/bin/bash
source /etc/profile


DATA=`date -d "1 week ago" +%Y.%m.%d`
curl --user elastic:passwd  -XDELETE http://xxx:9200/*-${DATA}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐