【问题标题】:How to transform a Kibana query to `elasticsearch_dsl` query如何将 Kibana 查询转换为“elasticsearch_dsl”查询
【发布时间】:2020-01-24 00:48:31
【问题描述】:

我有一个问题

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

【问题讨论】:

    标签: elasticsearch kibana elasticsearch-dsl elasticsearch-dsl-py


    【解决方案1】:

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

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

    【讨论】:

    • 对不起,我也在查询中开始了
    【解决方案2】:

    这个查询对我有用

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

    另外,如果键有_key_1 一样,弹性搜索的行为会有所不同,并且查询匹配结果,即使与您的查询不匹配。所以尽量选择没有下划线的key

    【讨论】:

      猜你喜欢
      • 2016-05-20
      • 2020-07-19
      • 2021-10-11
      • 2021-02-13
      • 2020-10-21
      • 2021-04-03
      • 2017-10-29
      • 2020-01-29
      • 2015-03-22
      相关资源
      最近更新 更多