首页 > 解决方案 > 在 Elasticsearch-dsl 中使用多个值匹配查询

问题描述

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

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

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

标签: elasticsearchelasticsearch-dslelasticsearch-dsl-py

解决方案


您可以使用术语查询而不是match查询,如下所示:

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

编辑:使用查询match

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

推荐阅读