问题描述
我在 Elastic 中有一个复杂的索引,我需要通过 3 个参数进行查询。
多亏了这个 answered question,我可以通过 3 个参数中的 2 个进行查询,但是第 3 个参数与其他两个参数不在同一嵌套级别。
以下查询适用于 3 个参数中的 2 个...
但是第三个参数与其他两个参数处于不同级别,因此此查询不会返回预期的文档。
鉴于“boundedContexts.aggregateRoot.aggregateType.name”的布尔匹配查询处于不同的嵌套级别,我将如何编写此查询以使其在该字段上进行查询?
解决方法
这有效...
{
"query": {
"nested": {
"path": "boundedContexts","query": {
"nested": {
"path": "boundedContexts.aggregateRoots","query": {
"bool": {
"must": [
{ "match": { "boundedContexts.aggregateRoots.aggregateType.name": "Aggregate" } },{ "nested": {
"path": "boundedContexts.aggregateRoots.modelMetaData","query": {
"bool": {
"must": [
{ "match": { "boundedContexts.aggregateRoots.modelMetaData.modelReferenceId": "4e7c5c0e-93a7-4bf6-9705-cf1327760e21" } },{ "match": { "boundedContexts.aggregateRoots.modelMetaData.modelType.name": "AggregateRoot" } }
]
}
}
}
}
]
}
}
}
}
}
},"size": 1,"sort": [
{
"generatedDate": {
"order": "desc"
}
}
] }