网站建设公司出路,戴尔网站建设成功的关键,erp软件公司,磁力狗在线引擎简介 脚本分2部分#xff0c;1部分查找符合条件的索引名#xff0c;2脚本调用1脚本#xff0c;进行删除操作 脚本 查找符合条件的#xff0c;默认大于30天 # coding:utf-8__author__ Jipu FANGfrom elasticsearch import Elasticsearch
import re
import time
import dat… 简介 脚本分2部分1部分查找符合条件的索引名2脚本调用1脚本进行删除操作 脚本 查找符合条件的默认大于30天 # coding:utf-8__author__ Jipu FANGfrom elasticsearch import Elasticsearch
import re
import time
import datetimenow time.localtime()
data1 datetime.datetime(now[0], now[1], now[2])esElasticsearch(http://192.168.30.135:9200)res es.cat.indices()l res.strip().split()
def dindex(day30):index []for i in l:if re.search(\d\.\d\.\d$, i):itime time.strptime(re.findall(\d\.\d\.\d$, i)[0], %Y.%m.%d)data2 datetime.datetime(itime[0], itime[1], itime[2])d (data1-data2).daysif int(d) int(day):index.append(i)return indexif __name__ __main__:print dindex()对符合条件的索引进行删除操作 # coding:utf-8__author__ Jipu FANGimport requests
import json
import time
from multiprocessing.dummy import Pool as ThreadPool
import re
import indexs
delect index url:http://192.168.30.135:9200/app-2017.05.16 headers:Content-Type: application/json data:{query: {match_all:{}}}
select log curl http://192.168.30.135:9200/_search headersContent-Type: application/json data{query: {match: {message: {query: ERROR|77 }}}
# request API
class ES_API:def __init__(self, url, data, headers):self.urlurlself.datadataself.headersheadersdef delete(self):r requests.delete(urlself.url, datajson.dumps(self.data), headersself.headers)vr.textprint(v)def post(self):r requests.post(urlself.url, datajson.dumps(self.data), headersself.headers)vr.textprint(v)# 删除索引day保留多少天
def delete_index(day):for i in indexs.dindex(day):url rhttp://192.168.30.135:9200/%s %(i)headers {Content-Type:application/json}data {query: {match_all:{}}}CES_API(url, data, headers)C.delete()time.sleep(3)return Delete indexs OK!# 关闭索引day保留多少天当索引处于关闭状态资源占用比较少
def close_index(day):for i in indexs.dindex(day):url rhttp://192.168.30.135:9200/%s/_close?pretty %(i)headers {Content-Type:application/json}data {}CES_API(url, data, headers)C.post()time.sleep(3)return index status close ok!delete_index(30)
time.sleep(60)
close_index(15) 转载于:https://www.cnblogs.com/GXLo/p/7405631.html