1
0

nested-aggregation.asciidoc 930 B

12345678910111213141516171819202122232425262728293031323334
  1. [[java-aggs-bucket-nested]]
  2. ==== Nested Aggregation
  3. Here is how you can use
  4. {ref}/search-aggregations-bucket-nested-aggregation.html[Nested Aggregation]
  5. with Java API.
  6. ===== Prepare aggregation request
  7. Here is an example on how to create the aggregation request:
  8. [source,java]
  9. --------------------------------------------------
  10. AggregationBuilders
  11. .nested("agg", "resellers");
  12. --------------------------------------------------
  13. ===== Use aggregation response
  14. Import Aggregation definition classes:
  15. [source,java]
  16. --------------------------------------------------
  17. import org.elasticsearch.search.aggregations.bucket.nested.Nested;
  18. --------------------------------------------------
  19. [source,java]
  20. --------------------------------------------------
  21. // sr is here your SearchResponse object
  22. Nested agg = sr.getAggregations().get("agg");
  23. agg.getDocCount(); // Doc count
  24. --------------------------------------------------