Facets

edit

Elasticsearch provides a full Java API to play with facets. See the Facets guide.

Use the factory for facet builders (FacetBuilders) and add each facet you want to compute when querying and add it to your search request:

SearchResponse sr = node.client().prepareSearch()
        .setQuery( /* your query */ )
        .addFacet( /* add a facet */ )
        .execute().actionGet();

Note that you can add more than one facet. See Search Java API for details.

To build facet requests, use FacetBuilders helpers. Just import them in your class:

import org.elasticsearch.search.facet.FacetBuilders.*;