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)
  • 相关阅读:
    event的属性
    dom三个事件
    setInterval和setTimeout定时器
    eclipse编码格式设置
    eclipse Subversion Native Library Not Available
    NET Framework V4.0.30319
    eclipse配置tomcat
    eclipse Multiple annotations found at this line
    eclipse安装svn插件
    eclipse安装maven
  • 原文地址:https://www.cnblogs.com/dreamer-fish/p/11202760.html
Copyright © 2011-2022 走看看