Complex nested Elastic NEST Query

女生的网名这么多〃 提交于 2021-01-29 15:45:05

问题


How would I convert this to the equivalent Nest query?

{
"query": {
    "nested": {
        "path": "boundedContexts",
        "query": {
            "nested": {
            "path": "boundedContexts.aggregateRoots",
                "query": {
                    "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"
    }
    }
]

}

I am trying to generate an equivalent Nest query similar to this ..

  ISearchResponse<ViewModels.DomainModel> response = null;
            response = await _elasticClient.SearchAsync<ViewModels.DomainModel>(s => s.Index(_modelMetadataProvider.CurrentIndexName)
            .Query(q => q.Nested(n1 => n1.Path("boundedContexts")
                .Query(q2 => q2.Nested(n2 => n2.Path("boundedContexts.aggregateRoots")
                    .Query(q3 => q3.Nested(n3 => n3.Path("boundedContexts.aggregateRoots.modelMetaData").
                       Query(q4 =>q4.Bool(b => b.Must(bs => 
                           bs.Match(p => p.Field("boundedContexts.aggregateRoots.modelMetaData.modelReferenceId")))))))))))
            .Size(1).Sort(s=>s.Descending("generatedDate")));

I am stuck on how to compare to a variable against at the p.Field("boundedContexts.aggregateRoots.modelMetaData.modelReferenceId") level of query.

来源:https://stackoverflow.com/questions/65727915/complex-nested-elastic-nest-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!