WARNING: Version 5.x has passed its EOL date.
This documentation is no longer being maintained and may be removed. If you are running this version, we strongly advise you to upgrade. For the latest information, see the current release documentation.
Nested aggregation
editNested aggregation
editA special single bucket aggregation that enables aggregating nested documents.
Fluent DSL
editvar result = client.Search<ElasticsearchProject>(s => s .Aggregations(a => a .Nested("my_nested_agg", n => n .Path("contributors") .Aggregations(aa => aa .Average("my_avg_agg", avg => avg .Field(p => p.Contributors.First().Age) ) ) ) ) ); var nestedAgg = result.Aggs.Nested("my_nested_agg"); var avgAgg = nestedAgg.Average("my_ avg_agg");
Object Initializer Syntax
editvar request = new SearchRequest { Aggregations = new Dictionary<string, IAggregationContainer> { { "my_nested_agg", new AggregationContainer { Nested = new NestedAggregator { Path = "contributors" }, Aggregations = new Dictionary<string, IAggregationContainer> { { "my_avg_agg", new AggregationContainer { Average = new AverageAggregator { Field = "contributors.age" } } } } } } } }; var result = client.Search<ElasticsearchProject>(request); var nestedAgg = result.Aggs.Nested("my_nested_agg"); var avgAgg = nestedAgg.Average("my_avg_agg");
Refer to the original docs for more information.