如何将 Kibana 查询转换为“elasticsearch_dsl”查询

How to transform a Kibana query to `elasticsearch_dsl` query

我有一个问题

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()

在我看来,您忘记了查询中的星星。

s = Search(index=index).query('wildcard', key='*match*').query('match', key=value)

这个查询对我有用

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

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