复杂的嵌套查询在哪里放置布尔匹配

问题描述

我在 Elastic 中有一个复杂的索引,我需要通过 3 个参数进行查询

多亏了这个 answered question,我可以通过 3 个参数中的 2 个进行查询,但是第 3 个参数与其他两个参数不在同一嵌套级别。

架构看起来是这样..

enter image description here

以下查询适用于 3 个参数中的 2 个...

enter image description here

但是第三个参数与其他两个参数处于不同级别,因此此查询不会返回预期的文档。

enter image description here

鉴于“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"
        }
    }

] }

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...