【发布时间】:2016-12-01 09:25:49
【问题描述】:
我有一个包含嵌套文档数组的文档。如果文档包含所有指定的嵌套文档,我需要返回匹配项。
这里是映射的相关部分:
"element": {
"dynamic": "false",
"properties": {
"tenantId": {
"type": "string",
"index": "not_analyzed"
},
"fqn": {
"type": "string",
"index": "not_analyzed"
},
"id": {
"type": "string",
"index": "not_analyzed"
},
"name": {
"type": "string",
"index": "not_analyzed"
},
"type": {
"type": "string",
"index": "not_analyzed"
},
"location": {
"type": "string",
"index": "not_analyzed"
},
"tags": {
"type": "nested",
"properties": {
"id": {
"type": "string",
"index": "not_analyzed"
},
"dataSourceId": {
"type": "long",
"index": "not_analyzed"
},
"name": {
"type": "string",
"index": "not_analyzed"
},
"value": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
}
目标是能够返回包含所有标签列表的元素(尽管允许该元素包含超出搜索要求的其他标签)。
这是我目前所拥有的:
{
"query": {
"bool": {
"filter": {
"nested": {
"path": "tags",
"query": {
"bool": {
"must": [
{
"bool": {
"must":{
"term": { "tags.name": "name1" },
"term": { "tags.value": "value1" }
}
}
},
{
"bool": {
"must":{
"term": { "tags.name": "name2" },
"term": { "tags.value": "value2" }
}
}
}
]
}
}
}
}
}
}
}
这种方法的问题是它返回 0 个具有多个标签值的命中(它适用于单个值)。我相信这是因为查询要求标签具有多个名称和值才能匹配,这显然不可能发生。有谁知道如何查询包含所有标签列表的元素?
编辑:这是使用弹性搜索 5.0
【问题讨论】:
-
@JamesKn 我查看了术语查询,但据我了解,它们是对值的隐式“或”操作。我需要一个“和”操作。
标签: elasticsearch