| 12345678910111213141516171819202122232425262728293031323334 | [[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", "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--------------------------------------------------
 |