如果遇到unassigned shared 可以通过以下命令,查询并将损坏的索引名称打印到文件内
curl -k -u elastic:elastic -XGET "http://192.168.45.11:9200/_cat/shards?" | grep UNASSIGNED >> needDelIndex.txt
通过删除脚本,修改esUrl的地址和端口、执行shell脚本,删除损坏的索引
#!/bin/bash
echo "$1"
esUrl=192.168.45.11:9200
indexfile=needDelIndex.txt
#cp -f /dev/null ${indexfile}
#curl -XGET ip:port/_cat/shards | grep UNASSIGNED >> needDelIndex.txt
if [ ! -f ./${indexfile} ]; then
echo $indexfile not exists
exit 0
fi
logfile=esindex_del.`date +"%m-%d"`.log
cp -f /dev/null ${logfile}
lastIndexName="test"
for item in `cat ${indexfile} | awk ‘{print $1}‘`
do
if [ "$item" = "error" ]
then
continue
fi
if [ "$item" != "$lastIndexName" ]
then
curl -k -u elastic:elastic -XDELETE ${esUrl}/${item} >> ${logfile}
echo ---------${item} `date` >> ${logfile}
sleep 5
fi
lastIndexName=${item}
done
原文:https://www.cnblogs.com/JanGuoon/p/14335765.html