【问题标题】:Complex Nested Query Where to Place Bool Match复杂的嵌套查询在哪里放置布尔匹配
【发布时间】:2021-01-15 23:15:06
【问题描述】:

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

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

架构看起来像这样..

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

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

鉴于“boundedContexts.aggregateRoot.aggregateType.name”的布尔匹配查询处于不同的嵌套级别,我将如何编写此查询以便查询该字段?

【问题讨论】:

  • 也许您可以将其分解为两个子查询,可以使用boolmust 进行复合。第一个子查询将在路径 boundedContexts.aggregateRoots.aggregateType 上,第二个在路径 boundedContexts.aggregateRoots.modelMetaData 您可以重复此模式以满足您的需要
  • 再次感谢@SaiGummaluri,我根据您的评论实施了一个可行的解决方案。干杯

标签: elasticsearch nest


【解决方案1】:

这行得通...

{
"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"
        }
    }

] }

【讨论】:

    猜你喜欢
    • 2011-02-19
    • 1970-01-01
    • 2018-04-28
    • 1970-01-01
    • 1970-01-01
    • 2018-08-13
    • 2018-07-29
    • 1970-01-01
    • 2012-11-29
    相关资源
    最近更新 更多