如何为elasticsearch嵌套使用两个并行聚合

how to use two parallel Aggregation for elasticsearch nest

喜欢下面的 http 请求: 基于 TERM "service_project" aggr,还有 2 个 SUM aggr "service_hour_price" 和 "servic_part_price"。我可以使用 Elasticsearch Nest 做同样的事情吗?

      "aggs": {
        "3": {
          "terms": {
            "field": "service_project",
            "size": 50,
            "order": {
              "1": "desc"
            }
          },
          "aggs": {
            "1": {
              "sum": {
                "field": "service_hour_price"
              }
            },
            "2": {
              "sum": {
                "field": "servic_part_price"
              }
            }
          }
        }
    }

现在我只能使用一个基于 That Term Aggr 的 SUM Aggr,如下所示:

                return s.Aggregations(a => a
                .Terms("names", st => st
                    .Field(o => o.service_project)
                    .OrderDescending("sum")
                    .Size(term_count)
                    .Aggregations(aa => aa
                        .Sum("sum", m => m
                            .Field(o => o.service_hour_price)))));

你快到了:

s.Aggregations(a => a
    .Terms("3", t => t
        .Field("service_project")
        .Size(50)
        .OrderDescending("1")
        .Aggregations(aa => aa
            .Sum("1", sum => sum.Field("service_hour_price"))
            .Sum("2", sum => sum.Field("service_part_price")))
    ));

希望对您有所帮助。