1、 #刪除指定索引
# curl -XDELETE -u elastic:changeme http://localhost:9200/acc-apply-2018.08.09
{"acknowledged":true}
2、#刪除多個指定索引,中間用逗號隔開
# curl -XDELETE -u elastic:changeme http://localhost:9200/acc-apply-2018.08.09,acc-apply-2018.08.10
3、#模糊匹配刪除
# curl -XDELETE -u elastic:changeme http://localhost:9200/acc-apply-*
{"acknowledged":true}
4、#使用通配符,刪除所有的索引
curl -XDELETE http://localhost:9200/_all
或 curl -XDELETE http://localhost:9200/*
_all ,* 通配所有的索引
通常不建議使用通配符,誤刪了后果就很嚴重了,所有的index都被刪除了
禁止通配符為了安全起見,可以在elasticsearch.yml配置文件中設置禁用_all和*通配符
action.destructive_requires_name = true
這樣就不能使用_all和*了
5、#獲取當前索引
# curl -u elastic:changeme 'localhost:9200/_cat/indices?v'
6、如果存儲不夠可以設置定時刪除,下面是保留3天的日志
30 2 * * * /usr/bin/curl -XDELETE -u elastic:changeme http://localhost:9200/*-$(date -d '-3days' +'%Y.%m.%d') >/dev/null 2>&1
以下是定時刪除腳本:
#!/bin/bash time=$(date -d '-3days' +'%Y.%m.%d') curl -XDELETE -u elastic:changeme http://localhost:9200/*-${time}