- Java Transport Client (deprecated): other versions:
- Preface
- Javadoc
- Maven Repository
- Client
- Document APIs
- Search API
- Aggregations
- Query DSL
- Java API Administration
NOTE: You are looking at documentation for an older release. For the latest information, see the current release documentation.
Using Aggregations
editUsing Aggregations
editThe following code shows how to add two aggregations within your search:
SearchResponse sr = client.prepareSearch() .setQuery(QueryBuilders.matchAllQuery()) .addAggregation( AggregationBuilders.terms("agg1").field("field") ) .addAggregation( AggregationBuilders.dateHistogram("agg2") .field("birth") .dateHistogramInterval(DateHistogramInterval.YEAR) ) .get(); // Get your facet results Terms agg1 = sr.getAggregations().get("agg1"); Histogram agg2 = sr.getAggregations().get("agg2");
See Aggregations Java API documentation for details.
Was this helpful?
Thank you for your feedback.