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打开)

#!/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)

猜你喜欢

转载自www.cnblogs.com/dreamer-fish/p/11202760.html