IMPORTANT: No additional bug fixes or documentation updates
will be released for this version. For the latest information, see the
current release documentation.
Nested Aggregation Usage
edit
IMPORTANT: This documentation is no longer updated. Refer to Elastic's version policy and the latest documentation.
Nested Aggregation Usage
editFluent DSL example
edita => 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 NestedAggregation("tags")
{
Path = "tags",
Aggregations = new TermsAggregation("tag_names")
{
Field = "tags.name"
}
}
Example json output.
{
"tags": {
"nested": {
"path": "tags"
},
"aggs": {
"tag_names": {
"terms": {
"field": "tags.name"
}
}
}
}
}
Handling Responses
editresponse.ShouldBeValid();
var tags = response.Aggregations.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);
}