我的目标是按时间戳对我从Elasticsearch收到的数百万条日志进行排序。
例子日志。
{"realIp": "192.168.0.2", "@timestamp": "2020-12-06T02:00:09.000Z"}
{"realIp": "192.168.0.2", "@timestamp": "2020-12-06T02:01:09.000Z"}
{"realIp": "192.168.0.2", "@timestamp": "2020-12-06T02:02:09.000Z"}
{"realIp": "192.168.0.2", "@timestamp": "2020-12-06T02:04:09.000Z"}
不幸的是,我无法将所有的日志从Elastic中整理出来。看来我必须自己来做。
我曾尝试过的办法是将数据整理出弹性。
es = Search(index="somelogs-*").using(client).params(preserve_order=True)
for hit in es.scan():
print(hit['@timestamp'])
另一种方法。
notifications = (es
.query("range", **{
"@timestamp": {
'gte': 'now-48h',
'lt' : 'now'
.sort("@timestamp")
.scan()
所以我在寻找一种方法,可以自己对这些日志进行排序,或者直接通过Elasticsearch进行排序。目前,我把所有的数据都保存在本地的 "logs.json "中,在我看来,我必须自己对其进行分类。