繁体   English   中英

如何将 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 具有_ like key_1弹性搜索的行为会有所不同,并且查询匹配结果,即使结果与您的查询不匹配。 所以尽量选择没有下划线的key

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM