我想找到一个带有名称的文档,该文档包含'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/