您的位置:首页 > 运维架构 > Shell

ES 集群清除索引 shell 脚本

2017-02-28 17:45 393 查看
ES 集群清除索引 Index 脚本,每个索引格式 "*-YYYY-mm-dd" ,输入截止Unix时间戳。

首先通过 indies 接口获取所有索引,然后遍历判断时间是否小于输入的 Unix 时间戳,是则执行删除索引。

#!/bin/bash
ip='192.168.1.1'
port=9200

endUnixTime=$1
indices=`curl -XGET "http://${ip}:${port}/_cat/indices" | awk '{print $3}'`
for index in ${indices[*]}
do
indexTime=${index##*-}
year=`echo ${indexTime} | cut -d "." -f1`
month=`echo ${indexTime} | cut -d "." -f2`
day=`echo ${indexTime} | cut -d "." -f3`

if [ ! $day ]
then
echo "ignore index:$index"
continue
fi

indexUnixTime=`date -d "$year$month$day" +%s`
if [ $indexUnixTime -lt $endUnixTime ]
then
echo "Delete index:$index"
curl -XDELETE "http://${ip}:${port}/$index"
fi
done
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: