首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带有术语和范围的elasticsearch-dsl-py查询过滤器

带有术语和范围的elasticsearch-dsl-py查询过滤器
EN

Stack Overflow用户
提问于 2020-05-15 22:02:11
回答 1查看 343关注 0票数 0

我正在尝试使用术语和范围以及query-string来过滤查询。筛选器(范围)和查询字符串有效,但筛选器(术语)无效。我做错了什么吗?

代码语言:javascript
复制
es = Elasticsearch([{'host': '192.168.121.121', 'port': 9200}])

index = Index("filebeat-*",using=es)
search = index.search()
searchStr = "OutOfMemoryError"

search = search.query("query_string", query=searchStr)
search = search.filter('range' ,  **{'@timestamp': {'gte': 1589399137000 , 'lt': 1589399377000, 'format' : 'epoch_millis'}})
search = search.filter('term'  , **{'can.deployment': 'can-*' })
response = search.execute(ignore_cache=True)
print(response.hits.total)
print(response.hits.hits._source.can.deployment)

json:

代码语言:javascript
复制
filter-term - ['hits']['hits']['_source']['can']['deployment']
filter-range- ['hits']['hits']['_source']['@timestamp']
代码语言:javascript
复制
{
  "hits" : {
    "total" : 138351328,
    "max_score" : 6.5700893,
    "hits" : [
      {
        "_index" : "filebeat-6.1.2-2020.05.13",
        "_type" : "doc",
        "_score" : 2.0166037,
        "_source" : {
          "@timestamp" : "2020-05-13T01:14:03.354Z",
          "source" : "/var/log/gw_rest/gw_rest.log",
          "message" : "[2020-05-13 01:14:03.354] WARN can_gw_rest [EventLoopGroup-3-2]: An exceptionCaught() event was fired.OutOfMemoryError,
          "fileset" : {...},
          "can" : {
            "level" : "WARN",
>>>>>>>>    "message" : "An exceptionCaught() event was fired- OutOfMemoryError,
            "timestamp" : "2020-05-13 01:14:03.354",
>>>>>>>>    "deployment" : "can-6b721b93965b-w3we4-4074-9903"
          }
        }
      }
    ]
  }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-05-16 21:49:55

我实际上不需要过滤器(术语)。这是可行的:

代码语言:javascript
复制
dIds=response['hits']['hits'][1]['_source']['can']['deployment']
print(dIds)
#loop through the response
for i in response['hits']['hits']:
          id = i['_source']['can']['deployment']
          print(id)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61821128

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档