ES以更新時間爲標準,分離數據

首先聲明……因各類緣由沒法使用python安裝es模塊,因此使用一種笨方法進行數據刪除……html

ES數據備份、遷移、導入可查看連接:http://www.javashuo.com/article/p-zgcinoht-mo.htmlpython

#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
@Create Time : 2020/4/1
@File Name : elasticsearch_del.py
@Author : Mr.yang
@Python Version : 2.7
@Software : PyCharm
"""

import time
import json

Time = '2020-03-01 00:00:00'
jsonfile = open('./備份出來的的索引.json', 'r')
file = open('./時間大於Time的.json', 'w')
nonefile = open('./無更新時間戳的.json', 'w')
nullfile = open('./更新時間戳爲null的.json', 'w')

def timestamp(times):
    if not times is None:
        timems = float(times/1000)
        time_local = time.localtime(timems)
        dt = time.strftime("%Y-%m-%d %H:%M:%S", time_local)
        if dt >= Time:
        g = json.dumps(line)
            file.write(g)
    else:
    d = json.dumps(line)
    nullfile.write(d)
    

for line in jsonfile:
    line = json.loads(line)
    s = line['_source']
    if s.has_key('updateTime'):
        timestamp(s['updateTime'])
    else:
        n = json.dumps(line)
        nonefile.write(n)
相關文章
相關標籤/搜索