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 Usage
editNested Aggregation Usage
editFluent DSL example
edits => s .Aggregations(a => a .Nested("tags", n => n .Path(p => p.Tags) .Aggregations(aa => aa .Terms("tag_names", t => t .Field(p => p.Tags.Suffix("name")) ) ) ) )
Object Initializer syntax example
editnew SearchRequest<Project> { Aggregations = new NestedAggregation("tags") { Path = "tags", Aggregations = new TermsAggregation("tag_names") { Field = "tags.name" } } }
Example json output.
{ "aggs": { "tags": { "nested": { "path": "tags" }, "aggs": { "tag_names": { "terms": { "field": "tags.name" } } } } } }
Handling Responses
editresponse.ShouldBeValid(); var tags = response.Aggs.Nested("tags"); tags.Should().NotBeNull(); var tagNames = tags.Terms("tag_names"); tagNames.Should().NotBeNull(); foreach(var item in tagNames.Buckets) { item.Key.Should().NotBeNullOrEmpty(); item.DocCount.Should().BeGreaterThan(0); }