#!/bin/bash
function es_clean() {
del_date=`date -d “30 day ago” +”%Y-%m-%d”`
date1=”$1 00:00:00″
date2=”$del_date 00:00:00″
t1=`date -d “$date1” +%s`
t2=`date -d “$date2” +%s`
if [ $t1 -le $t2 ]; then
echo “$1时间早于$del_date,删除”
format_date=`echo $1| sed ‘s/-/\./g’`
curl -XDELETE http://127.0.0.1:9200/*$format_date
fi
}
curl -XGET http://127.0.0.1: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
es_clean $LINE
done
本文链接地址: https://danteng.org/elasticsearch-clean-by-time-shell/