如何将特定的elasticsearch dsl查询转换为嵌套查询?

时间:2018-01-10 10:13:10

标签: c# elasticsearch nest dsl

如何将以下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"
          }
        }
       }
      }
     }
    }
   }
 }

有人会帮助我查询巢查询吗?提前谢谢你。

1 个答案:

答案 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))))))));