- Java Transport Client (deprecated): other versions:
- Preface
- Maven Repository
- Dealing with JAR dependency conflicts
- Embedding jar with dependencies
- Deploying in JBoss EAP6 module
- Client
- Document APIs
- Search API
- Count API
- Aggregations
- Percolate API
- Query DSL
- Indexed Scripts API
- Java API Administration
IMPORTANT: No additional bug fixes or documentation updates
will be released for this version. For the latest information, see the
current release documentation.
Using Aggregations
edit
IMPORTANT: This documentation is no longer updated. Refer to Elastic's version policy and the latest documentation.
Using 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") .interval(DateHistogramInterval.YEAR) ) .execute().actionGet(); // Get your facet results Terms agg1 = sr.getAggregations().get("agg1"); DateHistogram agg2 = sr.getAggregations().get("agg2");
See Aggregations Java API documentation for details.
Was this helpful?
Thank you for your feedback.