信息:
Filebeat安装在机器上,从这里可以读取日志并发送到弹性搜索服务器。在测试机器上,使用elasticsearch-dsl
,我读取日志并将其写入文件。在
问题:
来自机器的原始日志:
[Timestamp][INFO] AAAAAA
[Timestamp][INFO] BBBBBB
[Timestamp][INFO] CCCCCC
搜索日志并将其写入输出文件后:
^{pr2}$如何保持原样还是原样?在
代码:
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")
您需要按时间戳对日志进行排序。将搜索代码更改为:
当然,您需要更改
timestamp
以匹配您的时间戳字段。在相关问题 更多 >
编程相关推荐