es索引查询与删除

   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

 

posted @ 2020-05-09 14:38  客Ren  阅读(5367)  评论(0)    收藏  举报