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