ES删除索引

时间:2025-03-01 09:20:44
# ES删除索引API

例:删除所有为logstash的索引

[官方说明](/guide/en/elasticsearch/reference/current/)

```shell
curl -XDELETE ':9200/logstash-*'
```

# ES查看索引

```shell
curl ':9200/_cat/indices'
```

# 删除脚本

/home/trade/



```shell
#!/bin/bash

# 打印出所有索引,排除掉HF,fund
Indexs=`curl 'http://172.20.10.16:9200/_cat/indices' | awk '{print $3}' | egrep -v "^\." | egrep -v "^hf|^fund"`
# 20180203
# 要删除的截止日期
Curr_time="20180203"

for index in $Indexs:
do
echo $index | egrep "[0-9]{4}\.[0-9]{2}\.[0-9]{2}"
if [ $? == 0 ]
then
Now_time=`echo $index | egrep -o "[0-9]{4}\.[0-9]{2}\.[0-9]{2}"| awk -F'.' '{print $1$2$3}'`
if [[ $Curr_time -gt $Now_time ]]
then
curl -XDELETE ":9200/${index}"
fi
fi
done
```

备注 :定期删除日志: