elasticsearch - Elasticsearch bool查询必须匹配单个字段单个术语,另一个字段带有OR术语

标签 elasticsearch

我想找到一个带有名称的文档,该文档包含'Bob',并且其位置位于'paducah'或'smyrna'中。

这是我现在拥有的:

query: {
  bool: {
    must: [
      { match: { name: 'bob' } }, 
      { match: { location: ['paducah', 'smyrna'] } }
    ],
  },
},

我知道问题出在位置数组中,因为如果我将其更改为没有数组的单个元素,查询就可以正常工作。

This is the closest answer i could find

它不起作用,我收到以下错误:

[term] malformed query, expected [END_OBJECT] but found [FIELD_NAME]

最佳答案

您可以尝试以下查询:

{
    "query": {
      "bool": {
        "must": [
          { "match": { "name": "bob" } }
        ],
        "should": [
            { "match": { "location": "paducah" }},
            { "match": { "location": "smyrna"   }}
          ],
          "minimum_should_match": 1
      }
    }
}

关于elasticsearch - Elasticsearch bool查询必须匹配单个字段单个术语,另一个字段带有OR术语,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45266655/

相关文章:

typescript - 使用 typescript 向 AWS Elasticsearch Service 发出签名请求

lucene - ElasticSearch:根据字段长度过滤文档

java - ElasticSearch 和 JAVA_HOME

elasticsearch - Kibana没有显示任何来自Elasticsearch的数据

c# - Singleton ImplementationType:尝试激活时无法解析 'Nest.IElasticClient'类型的服务

elasticsearch - ElasticSearch Update因标签名称而失败?

solr - 测试从SOLR到Elasticsearch的数据传输

filter - Logstash替换@timestamp

elasticsearch - 从搜索结果中删除重复项

elasticsearch - 使用两个字段选择时间范围