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}

posted @ 2022-04-22 10:54  风儿飘  阅读(391)  评论(0编辑  收藏  举报