elasticsearch - 如何在 Elasticsearch Query 中传递特定字段的值列表

标签 elasticsearch elasticsearch-plugin elasticsearch-ruby

我有一个查询要搜索 provider_id来自 Elastic Search Cluster .我正在使用以下查询来获取单个 provider_id 的结果但在弄清楚如何传递提供者列表方面需要帮助。

{
"query": {
    "bool": {
        "must": [{
            "match": {
                "message.provider_id": {
                    "query": 943523,
                    "type": "phrase"
                }
            }
        }]
    }
}
}

假设我想搜索 provider_ids = [913523, 923523, 923523, 933523, 953523]那么我应该如何修改查询?

最佳答案

您可以将 provider_id 索引为 not_analyzed,然后使用术语查询:

POST /test_index/_search
{
    "query": {
        "terms": {
           "message.provider_id": [
              "913523", "923523", "923523", "933523", "953523"
           ]
        }
    }
}

或者如果您不需要分数,则作为带有过滤器的 bool 查询:
POST /test_index/_search
{
   "query": {
      "bool": {
         "filter": [
            {
               "terms": {
                  "message.provider_id": [
                      "913523", "923523", "923523", "933523", "953523"
                  ]
               }
            }
         ]
      }
   }
}

关于elasticsearch - 如何在 Elasticsearch Query 中传递特定字段的值列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39495593/

相关文章:

Elasticsearch - 停止分析器不允许数字

elasticsearch - 如何仅使用Shield访问仪表板选项卡以监控kibana中的图形?

elasticsearch 动态查询 - 为返回的每个文档添加另一个字段

elasticsearch - Elasticsearch排名短/相关标题少

ElasticSearch 嵌套查询 - 排除父文档

elasticsearch - 从 ElasticSearch 中按域获取 10 个最佳结果

elasticsearch - Elasticsearch如何排除分数= 0文档

javascript - 从Elasticsearch下载300,000+行作为.csv文件

pdf - 如何使用摄取附件插件在 Elasticsearch 5.0.0 中索引 pdf 文件?

elasticsearch - 如何使用elasticsearch-ruby gem在Elasticsearch中创建摄取管道