IMPORTANT: No additional bug fixes or documentation updates
will be released for this version. For the latest information, see the
current release documentation.
Using Facets
edit
IMPORTANT: This documentation is no longer updated. Refer to Elastic's version policy and the latest documentation.
Using Facets
editThe following code shows how to add two facets within your search:
SearchResponse sr = node.client().prepareSearch()
.setQuery(QueryBuilders.matchAllQuery())
.addFacet(FacetBuilders.termsFacet("f1").field("field"))
.addFacet(FacetBuilders.dateHistogramFacet("f2").field("birth").interval("year"))
.execute().actionGet();
// Get your facet results
TermsFacet f1 = (TermsFacet) sr.getFacets().facetsAsMap().get("f1");
DateHistogramFacet f2 = (DateHistogramFacet) sr.getFacets().facetsAsMap().get("f2");
See Facets Java API documentation for details.