【问题标题】:Matching query with multiple values in Elasticsearch-dsl在 Elasticsearch-dsl 中使用多个值匹配查询
【发布时间】:2019-11-13 17:09:03
【问题描述】:

我正在尝试编写一个查询,其中多个值应与该字段匹配。

在示例中,我尝试使用查询中的匹配字段获取所有月份的结果。我不知道的是,如何在 dsl 中编写此查询?

months = [2,3,4]
client = Elasticsearch()
    s = Search(using=client, index="namco_revenuestream")
s = s.query("match", month_period=months)

【问题讨论】:

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


    【解决方案1】:

    您可以使用terms query 代替match 查询如下:

    {
      "query": {
        "terms": {
          "month_period": [2,3,4]
        }
      }
    }
    

    编辑:使用match查询

    {
      "query": {
        "match": {
          "month_period": {
            "query": "2 3 4",
            "analyzer": "standard"
          }
        }
      }
    }
    

    【讨论】:

    • 嗨,我知道。但是,我想在 s = s.query("match", month_period=months),在 dsl 中这样做。
    • 使用匹配查询更新了答案。
    • 不,不一样。您正在使用值数组。我使用了所有值,每个值都用空格分隔为单个字符串值。
    猜你喜欢
    • 2013-11-10
    • 1970-01-01
    • 2021-08-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多