信息:
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")