批量删除es索引(索引格式为索引前缀-YYYY-mm-dd)

本文档展示了如何使用Shell脚本`cre_index.sh`和`del_Index.sh`来批量创建和删除Elasticsearch索引,索引名称以特定前缀和日期格式(如`gather-027-20170228`)组成。通过调整脚本参数,可以按需保留一定数量或时间段的索引。
摘要由CSDN通过智能技术生成

cre_index.sh

curl -XPUT 0.0.0.0:9200/gather-027-20170228
curl -XPUT 0.0.0.0:9200/gather-027-20170227
curl -XPUT 0.0.0.0:9200/gather-027-20170226
curl -XPUT 0.0.0.0:9200/gather-027-20170225
curl -XPUT 0.0.0.0:9200/gather-027-20170224
curl -XPUT 0.0.0.0:9200/gather-027-20170223
curl -XPUT 0.0.0.0:9200/gather-027-20170222
curl -XPUT 0.0.0.0:9200/gather-027-20170221
curl -XPUT 0.0.0.0:9200/gather-027-20170220
curl -XPUT 0.0.0.0:9200/gather-027-20170219
curl -XPUT 0.0.0.0:9200/gather-027-20170218

shell.py

import os


class Shell(object):
    def __init__(self,sh_path,host,port,index_pre,index_date,time_size,keep_count):
        self.shell = str(sh_path)
        self.host  = str(host)
        self.port  = str(port)
        self.index_pre = str(index_pre)
        self.index_date = str(index_date)
        self.time_size = str(time_size)
        self.keep_count = str(keep_count)
    def run_background(self):
        cmd_list=[]
        cmd_list.append(self.shell)
        cmd_list.append(self.host)
        cmd_list.append(self.port)
        cmd_list.append(self.index_pre)
        cmd_list.append(self.index_date)
        cmd_list.append(self.time_size)
        cmd_list.append(self.keep_count)
        pos = self.shell.rfind('/')+1
        #print(pos)
        #print(len(self.shell))
        sh_file = self.shell[pos:]
        exe = 'chmod +x '+sh_file
        #print(exe)
        os.system(exe)
        cmd = ' '.join(cmd_list)
        #print("cmd=&

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值