如何将以下DSL查询转换为c#NEST查询?
GET project/_search
{
"size": 0,
"aggs": {
"group_by_projectId": {
"filter": {
"terms": {
"projectId.keyword": ["1", "2", "18"]
}
},
"aggs": {
"project_tags": {
"terms": {
"field": "projectId.keyword",
"size": 100
},
"aggs": {
"last_process_time": {
"max": {
"field": "processedAt"
}
}
}
}
}
}
}
}
有人会帮助我查询巢查询吗?提前谢谢你。
答案 0 :(得分:2)
我已按如下方式转换查询,它完全正常:
_elasticClient.SearchAsync<Project>(s => s
.Size(0)
.Aggregations(a => a
.Filter("filter_by_projectId", f => f
.Filter(ff => ff
.Terms(t => t
.Field(tf => tf.ProjectId)
.Terms(projects
.Select(ps => ps.Id))))
.Aggregations(agg => agg
.Terms("group_by_projectId", st => st
.Field(o => o.ProjectId.Suffix("keyword"))
.Size(100)
.Aggregations(aa => aa
.Max("last_process_time", sa => sa
.Field(o => o.ProcessedAt))))))));