【发布时间】:2015-11-05 06:18:21
【问题描述】:
我在 elasticsearch 中有一些文档,其中包含键值对列表。以下是一些示例。
document 1:
{
data: [
{
key: key1,
value: value1
},
{
key: key1,
value: value2
},
]
}
document 2:
{
data: [
{
key: key2,
value: blah
},
{
key: key1,
value: value2
},
]
}
document 3:
{
data: [
{
key: key1,
value: value3
},
{
key: key1,
value: value2
},
{
key: key1,
value: somevalue
}
]
}
document 4:
{
data: [
{
key: key3,
value: blah
}
]
}
现在我想要所有具有 至少 2 个值 [value1, value2, value3] 和键 key1 的文档。
因此,从示例中,我需要文档 1 和 3,但 不是 2 或 4。
到目前为止,我的查询如下所示:
"query": {
"nested": {
"path": "data",
"query": {
"bool": {
"should": [
{
"bool": {
"must": [
{
"term": {
"key": key1
}
},
{
"term": {
"value": {
"value": "value1",
}
}
}
]
}
},
{
"bool": {
"must": [
{
"term": {
"key": key1
}
},
{
"term": {
"value": {
"value": "value2",
}
}
}
]
}
},
{
"bool": {
"must": [
{
"term": {
"key": key1
}
},
{
"term": {
"value": {
"value": "value3",
}
}
}
]
}
}
],
"minimum_number_should_match": 2
}
}
}
}
但它根本不返回任何匹配项。
据我了解,minimum_number_should_match 只是确保仅当文档至少匹配bool query 中给定的最小should 出现次数时才会返回。
但我似乎并不完全理解它是如何工作的。
我究竟如何让minimum_number_should_match 使用嵌套布尔查询,或者有其他方法可以做到这一点?
【问题讨论】:
标签: elasticsearch