ElasticSearch查看刪除關閉索引

curl -XDELETE 'http://10.1.2.2:9200/iis_log_2019-07'     #刪除名爲/iis_log_2019-07的索引python

curl -XPOST 'http://10.1.2.2:9200/iis_log_2019-07/_close/'   #關閉名爲/iis_log_2019-07的索引(_open打開)curl

curl  10.1.2.2:9200/_cat/indices/iis_log* #查看iis_log開頭的全部索引url

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

#!/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)
相關文章
相關標籤/搜索