elasticsearch删除索引时报错"wildcard expressions or all indices are not allowed"

 

 

在做es集群的索引定时7天删除的时候

自己写了一个shell脚本

#/bin/bash
#指定日期(7天前)
DATA=`date -d "1 week ago" +%Y.%m.%d`
#当前日期
time=`date`
#删除7天前的
#curl -XGET "http://ip:9200/_cat/indices/?v"|grep $DATA

if [ $? -eq 0 ];then
    curl -XDELETE http://ip:9200/*-${DATA}
 echo "于 $time 清理 testlog-$DATA 索引!"  >> /home/idouall/es-index-sucess-clear.log
 echo "清理完毕============="
fi

结果执行的时候一直报一个错

wildcard expressions or all indices are not allowed

查了网上的各种资料,看到如下解释.

elasticsearch删除索引时报错

然后就把elasticsearch.yml的的action.destructive_requires_name设置为false重启.

发现没卵用.

然后没办法只好自己做完全匹配如下:如下,开始删除下面将自己要删除的前缀和后缀拼成完整的路径文件.就可以删除成功了.

 

#!/bin/bash
# Remove the index of one month old in elasticserch
CMD_ECHO='echo'
SCRIPT_NAME=`basename $0`
LOG_PRINT="eval $CMD_ECHO \"[$SCRIPT_NAME]\" @$(date +"%Y%m%d %T") [INFO] :"
time_ago=7
es_cluster_ip=10.26.22.130
function delete_index(){
    comp_date=`date -d "${time_ago} day ago" +"%Y-%m-%d"`
    date1="${1} 00:00:00"
    date2="${comp_date} 00:00:00"
    index_date=`date -d "${date1}" +%s`
    limit_date=`date -d "${date2}" +%s`
    if [ $index_date -le $limit_date ];then
            $LOG_PRINT  "$1 will perform the delete task earlier than  ${time_ago} days ago" >> tmp.txt
            del_date=`echo $1 | awk -F  "-" '{print $1"."$2"."$3}'`
            echo "=========开始删除========="
            curl -XDELETE http://${es_cluster_ip}:9200/devlog-$del_date >> tmp.txt
            curl -XDELETE http://${es_cluster_ip}:9200/devbacklog-$del_date >> tmp.txt
            curl -XDELETE http://${es_cluster_ip}:9200/testlog-$del_date >> tmp.txt
            curl -XDELETE http://${es_cluster_ip}:9200/testbacklog-$del_date >> tmp.txt
            curl -XDELETE http://${es_cluster_ip}:9200/uatbacklog-$del_date >> tmp.txt
            curl -XDELETE http://${es_cluster_ip}:9200/uatlog-$del_date >> tmp.txt
            curl -XDELETE http://${es_cluster_ip}:9200/prodlog-$del_date >> tmp.txt
            curl -XDELETE http://${es_cluster_ip}:9200/prodbacklog-$del_date >> tmp.txt
            curl -XDELETE http://${es_cluster_ip}:9200/alllogback-$del_date >> tmp.txt
    fi
}

                                                     # get the date in all index
curl -XGET http://${es_cluster_ip}:9200/_cat/indices|awk -F " " '{print $3}'  | egrep "[0-9]*\.[0-9]*\.[0-9]*" |awk -F  "-" '{print $NF}' | awk -F  "." '{print $((NF-2))"-"$((NF-1))"-"$NF}' | sort | uniq | while read LINE   
do
   delete_index  ${LINE}
done

 

 

 

 

 

 

 

你可能感兴趣的:(elasticsearch删除索引时报错"wildcard expressions or all indices are not allowed")