python - 定时清理ES 索引,python清理es索引,只保留三天#!/us
python - 定时清理ES 索引,python清理es索引,只保留三天#!/us
只保留三天
#!/usr/bin/env python3# -*- coding:utf-8 -*-import osimport datetime# 时间转化为字符串now_time = datetime.datetime.now().strptime(datetime.datetime.now().strftime("%Y.%m.%d"),"%Y.%m.%d")os.system("curl -XGET http://127.0.0.1:9200/_cat/indices > date.txt")with open("date.txt","r") as f: for line in f.readlines(): index = line.strip().split()[2] try: index_strftime = datetime.datetime.strptime(index.split("-")[-1], "%Y.%m.%d") Ca = (now_time - index_strftime) if str(Ca).split()[0] == "0:00:00": continue elif int(str(Ca).split()[0]) >= 3: command = "curl -XDELETE http://127.0.0.1:9200/%s" % index print(command) os.system(command) else: print(index,"no del") except: pass
加入到定时任务即可
python - 定时清理ES 索引
相关内容
- 分享 《利用Python进行数据分析(第二版)》高清中文版
- python重定向原理及实例,python重定向实例,1. 前言为了在
- python3--网络爬虫--爬取图片,python3--爬虫--爬,网上大多
- python之图片文字识别,python文字识别,总体思路:
- Python 帮你玩微信跳一跳 GitHub Python脚本,githubpython,前言
- python基础数据类型,,1,int #数字(
- Python--妯″潡涔媡ime銆乺andom銆乷s銆乭ashlib,python--ha
- python 人脸检测 +python 二维码检测,python人脸检测,从官
- python:多进程、多线程,,线程&进程对于操作系
- Python爬取全书网小说,免费看小说,,什么是网络爬虫网
评论关闭