提问者:小点点

如何通过python从filebeat索引中获取选定的日志


我使用python elasticsearch模块搜索filebeat日志使用使用关键字.同我做"Kibana发现"但我的搜索不返回任何东西。

# make sure ES is up and running
import requests
res = requests.get('http://xxxxx:9200')
print(res.content)


# Import Elasticsearch package 
from elasticsearch import Elasticsearch 
# Connect to the elastic cluster

es=Elasticsearch([{'host':'xxxxx','port':9200}],timeout=30)
es

es.search(index='*',  body={
  'query': {
    'match': {
      'message': 'SocketTimeoutException',
     }
  }
})

es

它应该给我这样的日志文件,但它没有。

消息: 14:20:01,387错误[com.yuma.jca.socket.concox](默认线程-37)消息工作SocketTimeoutException for imei:0358735075610732-

但我得到的只是指纹的联系

b'{\n"name":"kibana",\n"cluster_name":"elasticsearch",\n"cluster_uuid":"pspfiiegRre8OFSsLWIhQ",\n"version":{\n"number":"7.2.0",\n"build_flavor":"default",\n"build_type":"deb",\n"build_hash":"508c38a",\n"build_date":"2019-06-20T15:54:18.811730Z",\n"build_snapshot":false,\n"lucene_version":"8.0.0",\n"minimum_wire_compatibility_version":"6.8.0",\n"minimum_index_compatibility_version":"6.0.0-beta1"\n},\n"标语":"你知道,用于搜索"\n}\n'


共1个答案

匿名用户

将elasticsearch查询的结果分配到一个变量中并打印响应数据。

data = es.search(index='*',  body={
  'query': {
    'match': {
      'message': 'SocketTimeoutException',
     }
  }
})
print(data)