children-aggregation.asciidoc 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. [[java-aggs-bucket-children]]
  2. ==== Children Aggregation
  3. Here is how you can use
  4. {ref}/search-aggregations-bucket-children-aggregation.html[Children 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. AggregationBuilder aggregation =
  11. AggregationBuilders
  12. .children("agg", "reseller"); <1>
  13. --------------------------------------------------
  14. 1. `"agg"` is the name of the aggregation and `"reseller"` is the child type
  15. ===== Use aggregation response
  16. Import Aggregation definition classes:
  17. [source,java]
  18. --------------------------------------------------
  19. import org.elasticsearch.join.aggregations.Children;
  20. --------------------------------------------------
  21. [source,java]
  22. --------------------------------------------------
  23. // sr is here your SearchResponse object
  24. Children agg = sr.getAggregations().get("agg");
  25. agg.getDocCount(); // Doc count
  26. --------------------------------------------------