为了尽量最大使用磁盘空间,索引的生存时间设置为最大,当磁盘使用达到一定的比例时,用shell脚本删除索引
#!/bin/sh
diskLeft=`df -h | grep xxhlog(替换你自己的磁盘标识) | awk '{print substr($5,1,2)}'`
if [ $diskLeft -gt 85 ]
then
top1Index=`curl 'yourIP:9200/_cat/indices?v' | grep myfilebeat | awk '{print $3 | "sort -n"}' | head -1`
sleep 3s
echo 'delete the top 1 index : ' + $top1Index >> delete.log
echo "yourIP:9200/$top1Index?pretty" >> delete.log
curl -XDELETE "yourIP:9200/$top1Index?pretty"
else
echo 'disk left is enough ' >> delete.log
fi