IMPORTANT: No additional bug fixes or documentation updates
will be released for this version. For the latest information, see the
current release documentation.
Facet filters (not Filter Facet)
edit
IMPORTANT: This documentation is no longer updated. Refer to Elastic's version policy and the latest documentation.
Facet filters (not Filter Facet)
editBy default, facets are applied on the query resultset whatever filters exists or are.
If you need to compute facets with the same filters or even with other
filters, you can add the filter to any facet using
AbstractFacetBuilder#facetFilter(FilterBuilder) method:
FacetBuilders
.termsFacet("f").field("brand") // Your facet
.facetFilter( // Your filter here
FilterBuilders.termFilter("colour", "pale")
);
For example, you can reuse the same filter you created for your query:
// A common filter
FilterBuilder filter = FilterBuilders.termFilter("colour", "pale");
TermsFacetBuilder facet = FacetBuilders.termsFacet("f")
.field("brand")
.facetFilter(filter); // We apply it to the facet
SearchResponse sr = node.client().prepareSearch()
.setQuery(QueryBuilders.matchAllQuery())
.setFilter(filter) // We apply it to the query
.addFacet(facet)
.execute().actionGet();
See documentation on how to build Filters.