es刪除索引


 

批量刪

配置文件:action.destructive_requires_name true(不能批量刪除)  false(可以批量刪)

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

 

單個刪

curl --user elastic:pss  -XDELETE http://ip:9200/$line$format_date

 

#!/bin/bash
source /etc/profile
#定義刪除30天以前的函數
delete_indices(){
check_day=`date -d '-15 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'`
while read line
curl --user elastic:pass  -XDELETE http://IP:9200/$line$format_date
done<test
fi
}
curl --user elastic:pass -XGET http://IP:9200/_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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM