如何使用两个并行聚合for elasticsearch nest

时间:2015-11-17 16:36:28

标签: elasticsearch nest elasticsearch-net

喜欢下面的http请求: 基于TERM" service_project" aggr,还有另外两个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)))));

1 个答案:

答案 0 :(得分:0)

你快到了:

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")))
    ));

希望它有所帮助。