如何在嵌套对象上创建ElasticSearch
过滤器查询,以使结果与两者匹配?
我有包含嵌套对象的文档,如下所示:
{
"objectNumber": "1","nestedObjects": [
{
"category": "position","tag": "2300"
},{
"category": "scope","tag": "External"
}
]
}
{
"objectNumber": "2","nestedObjects": [
{
"category": "position","tag": "2300"
},{
"category": "scope","tag": "Internal"
}
]
}
{
"objectNumber": "3","tag": "Internal"
}
]
}
我想执行一个查询,该查询仅返回包含带有category=position
和tag=2300
的嵌套对象以及带有category=scope
和tag=Internal
的嵌套对象的文档。 objectNumber
2和3,但不是1。
我已经了解到了:
{
"query": {
"nested": {
"path": "tags","query": {
"bool": {
"should": [
{
"bool": {
"filter": [
{
"match": {
"tags.category": "position"
}
},{
"match": {
"tags.tag": "2200"
}
},{
"match": {
"tags.category": "scope"
}
},{
"match": {
"tags.tag": "Internal"
}
}
]
}
}
]
}
}
}
}
}
将返回所有3个对象,而不仅仅是2和3。任何帮助将不胜感激。