zoukankan      html  css  js  c++  java
  • ElasticSearch查看删除关闭索引

    curl -XDELETE 'http://10.1.2.2:9200/iis_log_2019-07'     #删除名为/iis_log_2019-07的索引

    curl -XPOST 'http://10.1.2.2:9200/iis_log_2019-07/_close/'   #关闭名为/iis_log_2019-07的索引(_open打开)

    curl  10.1.2.2:9200/_cat/indices/iis_log* #查看iis_log开头的所有索引

    curl  10.1.2.2:9200/_cat/indices/iis_log_2018-07' #查看iis_log_2018-07的索引

    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    import datetime,os
    from dateutil.relativedelta import relativedelta
    
    #关闭前第3个月的索引
    def index_close(indexname,hmonths):
        dt_m = (datetime.date.today() - relativedelta(months=hmonths)).strftime('%Y-%m')
        iname = '%s_%s' % (indexname,dt_m)
        url = 'http://10.1.2.2:9200/%s/_close/' % iname
        print(url)
        m = os.popen('curl -XPOST %s' % url)
        print(m.readlines())
    
    # index_close('iis_logl',3)
    
    #删除前第12个月的索引
    def index_delete(indexname,hmonths):
        dt_m = (datetime.date.today() - relativedelta(months=hmonths)).strftime('%Y-%m')
        iname = '%s_%s' % (indexname,dt_m)
        url = 'http://10.1.2.2:9200/%s' % iname
        print(url)
        m = os.popen('curl -XDELETE %s' % url)
        print(m.readlines())
    
    index_delete('iis_log',12)
    #关闭前1个月的索引,索引以天为单位产生,如sec_mail_2020-04-28)
    def index_close_days(indexname,nmonths):
            dt_m = (datetime.date.today() - relativedelta(months=nmonths)).strftime('%Y-%m')
            dt_n = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
            y,m = dt_m.split('-')
            days = (calendar.monthrange(int(y),int(m)))[1]
            for d in range(days):
                d = str(d+1).rjust(2,'0')
                iname = '%s_%s-%s' % (indexname,dt_m,d)
                url = 'http://10.1.2.2:9200/%s/_close/' % iname
                # print(url)
                rs = os.popen('curl -XPOST %s' % url)
                with open(logfile,'a') as fw:
                    fw.write('%s
    %s
    %s
    '% (dt_n,url,rs.read()))
    
    #删除前3个月的索引,索引以天为单位产生,如sec_mail_2020-04-28)
    def index_delete_days(indexname,nmonths):
            dt_m = (datetime.date.today() - relativedelta(months=nmonths)).strftime('%Y-%m')
            dt_n = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
            y,m = dt_m.split('-')
            days = (calendar.monthrange(int(y),int(m)))[1]
            for d in range(days):
                d = str(d+1).rjust(2,'0')
                iname = '%s_%s-%s' % (indexname,dt_m,d)
                url = 'http://10.1.2.2:9200/%s' % iname
                # print(url)
                rs = os.popen('curl -XDELETE %s' % url)
                with open(logfile,'a') as fw:
                    fw.write('%s
    %s
    %s
    '% (dt_n,url,rs.read()))
    
    index_close_days('sec_mail',1)
    index_delete_days('sec_mail',3)
  • 相关阅读:
    ASP.NET Core多环境配置文件问题
    .NET Core中Object Pool的简单使用
    Refit在ASP.NET Core中的实践
    HttpClientFactory与Steeltoe结合来完成服务发现
    用HttpClientFactory来实现简单的熔断降级
    看看.NET Core几个Options的简单使用
    再探Circuit Breaker之使用Polly
    谈谈Circuit Breaker在.NET Core中的简单应用
    在.NET Core中使用简单的插件化机制
    谈谈ASP.NET Core中的ResponseCaching
  • 原文地址:https://www.cnblogs.com/dreamer-fish/p/11202760.html
Copyright © 2011-2022 走看看