NOTE: You are looking at documentation for an older release. For the latest information, see the current release documentation.
Parent Aggregation Usageedit
A special single bucket aggregation that selects parent documents that have the specified type, as defined in a join
field.
Be sure to read the Elasticsearch documentation on Parent Aggregation.
Fluent DSL exampleedit
Object Initializer syntax exampleedit
new ParentAggregation("name_of_parent_agg", typeof(CommitActivity)) { Aggregations = new AverageAggregation("average_commits", Field<Project>(f => f.NumberOfCommits)) && new MaxAggregation("max_commits", Field<Project>(f => f.NumberOfCommits)) && new MinAggregation("min_commits", Field<Project>(f => f.NumberOfCommits)) }
|
|
sub-aggregations are on the type determined from the |
Example json output.
{ "size": 0, "aggs": { "name_of_parent_agg": { "parent": { "type": "commits" }, "aggs": { "average_commits": { "avg": { "field": "numberOfCommits" } }, "max_commits": { "max": { "field": "numberOfCommits" } }, "min_commits": { "min": { "field": "numberOfCommits" } } } } } }
Handling Responsesedit
response.ShouldBeValid(); var parentAgg = response.Aggregations.Parent("name_of_parent_agg"); parentAgg.Should().NotBeNull(); parentAgg.DocCount.Should().BeGreaterThan(0); parentAgg.Min("average_commits").Should().NotBeNull(); parentAgg.Min("min_commits").Should().NotBeNull(); parentAgg.Max("max_commits").Should().NotBeNull();