1、 #刪除單個索引
# curl -XDELETE -u elastic:elasticpasswd http://localhost:9200/index_name {"acknowledged":true}
2、#刪除多個指定索引,中間用逗號隔開
# curl -XDELETE -u elastic:elasticpasswd http://localhost:9200/index_name_01,index_name_02
3、#模糊匹配刪除
# curl -XDELETE -u elastic:elasticpasswd http://localhost:9200/index_name* {"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:elasticpasswd 'localhost:9200/_cat/indices?v'
6、如果存儲不夠可以設置定時刪除,下面是保留3天的日志
以下是定時刪除腳本:
#!/bin/bash time=$(date -d '-3days' +'%Y.%m.%d') curl -XDELETE -u elastic:changeme http://localhost:9200/*-${time}
添加計划任務
10 1 * * * /usr/bin/curl -XDELETE -u elastic:elasticpasswd http://localhost:9200/*-$(date -d '-3days' +'%Y.%m.%d') >/dev/null 2>&1