安装机器上从那里日志将被读取并送给弹性搜索服务器Filebeat。从测试机器上,使用elasticsearch-dsl
,我正在读取日志并将其写入文件。
问题:
原稿登录从机:
[Timestamp][INFO] AAAAAA
[Timestamp][INFO] BBBBBB
[Timestamp][INFO] CCCCCC
搜索和日志写入输出文件后:
[Timestamp][INFO] CCCCCC
[Timestamp][INFO] AAAAAA
[Timestamp][INFO] BBBBBB
如何保持日志序列完整或它是?
代码:
from elasticsearch import Elasticsearch
from elasticsearch_dsl import Search, Q, Index
import time
#Make Connection
es = Elasticsearch(["100.16.13.222:9200"])
#Create Index Object
ind = Index("filebeat-*",using=es)
#Clear Cache
ind.clear_cache()
#Create Search object for this index
sear = ind.search()
#Create query
sear = sear.query("match",host="WIN-LK9FS7568K4").query("match",tags="old_log")
res = sear.execute(ignore_cache=True)
print int(res.hits.total)
with open("a.txt","w") as fh:
for i in sear.scan():
fh.write(i.message+"\n")
在您的搜索中,您需要按时间戳排序日志 – Val
Val - 将会有两个时间戳。由于弹性搜索和日志时间戳的时间戳。如何使用日志的时间戳进行排序? –
@Val - 你能帮我吗。如何使用python elasticsearch-dsl在查询中使用regexp? –