手动删除Elasticsearch索引删除
- 登录ES服务器,获取当前索引,并过滤出需要删除的索引名称。
curl -XGET -u user:password 'http://IP:9200/_cat/shards'|grep 2023.01|awk '{print $1}'|uniq > /tmp/ES_index.tmp
- 使用脚本删除索引。
cat /scripts/del_elasticseatch_index.sh
for ES_index_name in `cat /tmp/ES_index.tmp`
do
echo $ES_index_name
curl -XDELETE -u user:password http://IP:9200/$ES_index_name
echo "${ES_index_name} delete success" >> /tmp/del_elasticseatch_index.log
done
自动删除Elasticsearch索引删除
- 设置定时计划任务,自动删除索引。
crontab -e
30 2 * * * /usr/bin/curl -XDELETE -u user:password http://IP:9200/*-$(date -d '-100days' +'%Y.%m.%d') >/dev/null 2>&1