【问题标题】:elasticsearch-dsl-py query filter with term and rangeelasticsearch-dsl-py 带有术语和范围的查询过滤器
【发布时间】:2020-09-01 09:22:41
【问题描述】:

我正在尝试过滤带有术语和范围以及查询字符串的查询。过滤器(范围)和查询字符串有效,但过滤器(术语)无效。我是不是做错了什么?

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:

filter-term - ['hits']['hits']['_source']['can']['deployment']
filter-range- ['hits']['hits']['_source']['@timestamp']
{
  "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"
          }
        }
      }
    ]
  }
}

【问题讨论】:

    标签: python-2.7 elasticsearch elasticsearch-dsl


    【解决方案1】:

    我实际上不需要过滤器(术语)。这有效:

    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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-07
      • 1970-01-01
      • 1970-01-01
      • 2021-05-20
      相关资源
      最近更新 更多