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)
  • 相关阅读:
    java进阶知识--File类
    java进阶知识--函数式接口
    java进阶知识--Lambda表达式、递归
    java进阶知识--线程池
    java进阶知识--线程安全
    java进阶知识--多线程入门
    java基础知识--异常
    java基础知识--可变参数
    mysql中如何不重复插入满足某些条件的重复的记录的问题
    有关map中使用iterate迭代器遍历的不保序问题和list remove(object)的细节问题
  • 原文地址:https://www.cnblogs.com/dreamer-fish/p/11202760.html
Copyright © 2011-2022 走看看