Executing a facet search
The previous recipe can be extended to support facet and to retrieve analytics on indexed data.
Getting ready
You need a working ElasticSearch cluster and a working copy of Maven.
The code of this recipe is in chapter_10/nativeclient in the code bundle of this book available on Packt's website and the referred class is FacetExample
.
How to do it...
For executing a facet search, we will perform the steps given as follows:
- We'll calculate two different facets (term and statistical):
import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.client.Client; import org.elasticsearch.search.facet.FacetBuilder; import org.elasticsearch.search.facet.statistical.StatisticalFacet; import org.elasticsearch.search.facet.terms.TermsFacet; import static org.elasticsearch.index.query.QueryBuilders.*; import static org.elasticsearch.search.facet.FacetBuilders.*; public class FacetExample { public static void main(String[] args) { … Client...