首页 > 解决方案 > 如何将 Kibana 查询转换为“elasticsearch_dsl”查询

问题描述

我有一个查询

GET index/_search

{
  "query": {
    "bool": {
      "should": [
        {
          "match": {
            "key1": "value"
          }
        },
        {
          "wildcard": {
            "key2": "*match*"
          }
        }
      ]
    }
  }
}

我想用elasticsearch_dsl我试过的包打同样的电话

s = Search(index=index).query({
    "bool": {
      "should": [
        {
          "match": {
            "key1": "value"
          }
        },
        {
          "wildcard": {
            "key2": "*match*"
          }
        }
      ]
    }
  })
s.using(self.client).scan()

但是结果不一样,我在这里遗漏了什么吗

有没有办法用elasticsearch_dsl 这个来表示我的查询,没有结果

s = Search(index=index).query('wildcard', key2='*match*').query('match', key1=value)
s.using(self.client).scan()

标签: elasticsearchkibanaelasticsearch-dslelasticsearch-dsl-py

解决方案


这个查询对我有用

s = Search(index=index).query('match', key1=value)
                       .query('wildcard', key2='*match*')
                       .source(fields)

此外,如果键具有_类似key_1弹性搜索的行为不同并且查询匹配结果,即使与您的查询不匹配。所以尽量选择你key没有下划线的。


推荐阅读