| 123456789101112131415161718192021222324252627282930313233343536 | [[java-aggs-bucket-nested]]==== Nested AggregationHere is how you can use{ref}/search-aggregations-bucket-nested-aggregation.html[Nested Aggregation]with Java API.===== Prepare aggregation requestHere is an example on how to create the aggregation request:[source,java]--------------------------------------------------AggregationBuilders    .nested("agg")    .path("resellers");--------------------------------------------------===== Use aggregation responseImport Aggregation definition classes:[source,java]--------------------------------------------------import org.elasticsearch.search.aggregations.bucket.nested.Nested;--------------------------------------------------[source,java]--------------------------------------------------// sr is here your SearchResponse objectNested agg = sr.getAggregations().get("agg");agg.getDocCount(); // Doc count--------------------------------------------------
 |