2014-05-15 06:36:05 -04:00
|
|
|
[[java-aggs-bucket-children]]
|
|
|
|
==== Children Aggregation
|
|
|
|
|
|
|
|
Here is how you can use
|
|
|
|
{ref}/search-aggregations-bucket-children-aggregation.html[Children Aggregation]
|
|
|
|
with Java API.
|
|
|
|
|
|
|
|
|
|
|
|
===== Prepare aggregation request
|
|
|
|
|
|
|
|
Here is an example on how to create the aggregation request:
|
|
|
|
|
|
|
|
[source,java]
|
|
|
|
--------------------------------------------------
|
|
|
|
AggregationBuilder aggregation =
|
|
|
|
AggregationBuilders
|
2016-02-12 08:54:10 -05:00
|
|
|
.children("agg", "reseller"); <1>
|
2014-05-15 06:36:05 -04:00
|
|
|
--------------------------------------------------
|
2016-02-12 08:54:10 -05:00
|
|
|
1. `"agg"` is the name of the aggregation and `"reseller"` is the child type
|
2014-05-15 06:36:05 -04:00
|
|
|
|
|
|
|
===== Use aggregation response
|
|
|
|
|
|
|
|
Import Aggregation definition classes:
|
|
|
|
|
|
|
|
[source,java]
|
|
|
|
--------------------------------------------------
|
|
|
|
import org.elasticsearch.search.aggregations.bucket.children.Children;
|
|
|
|
--------------------------------------------------
|
|
|
|
|
|
|
|
[source,java]
|
|
|
|
--------------------------------------------------
|
|
|
|
// sr is here your SearchResponse object
|
|
|
|
Children agg = sr.getAggregations().get("agg");
|
|
|
|
agg.getDocCount(); // Doc count
|
|
|
|
--------------------------------------------------
|