Executing a search with aggregations
The previous recipe can be extended to support aggregations and to retrieve analytics on indexed data.
Getting ready
You will need a working ElasticSearch cluster and a working copy of Maven.
The code of this recipe is in chapter_10/nativeclient
folder in the code bundle of this chapter available on Packt's website, and on GitHub (https://github.com/aparo/elasticsearch-cookbook-second-edition). The referred class is AggregationExample
.
How to do it...
To execute a search with aggregations, we will perform the following steps:
- We'll calculate two different aggregations (terms and extended statistics) as follows:
import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.client.Client; import org.elasticsearch.search.aggregations.AggregationBuilder; ...
Get ElasticSearch Cookbook - Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.