Step 1: configure filterable attributes
Only attributes listed infilterableAttributes can be used as facets. Suppose you have a books index with documents like this:
filterableAttributes:
Step 2: request facet distributions
Use thefacets search parameter to tell Meilisearch which attributes should include distribution counts in the response:
facetDistribution object showing every value for each requested facet and how many documents match:
facetDistribution tells you exactly which values exist and how many documents match each one. The facetStats object provides minimum and maximum values for numeric facets, useful for building range sliders.
Step 3: apply a filter when the user clicks a facet
When a user clicks a facet value, send a new search request with afilter parameter:
hits and the facetDistribution to reflect the active filter. This means the facet counts adjust dynamically, showing users how many results remain for each option.
Step 4: combine multiple facet filters
Users often select multiple facet values. Combine them usingAND and OR operators:
AND to require all conditions (narrow results) and OR to match any condition (broaden results within a facet group). See the filter expression syntax reference for the full list of operators:
Frontend implementation pattern
Here is a JavaScript pattern for building an interactive faceted sidebar:- Tracks active filter selections in an
activeFiltersobject - Builds a filter string from active selections on each search
- Renders facet values as checkboxes with document counts
- Updates both facets and results when the user toggles a checkbox
Key points
- Always include the
facetsparameter in every search request so the sidebar stays updated - Facet counts reflect the current filter state, so users see accurate numbers
- Use
ORwithin the same attribute (for example, multiple genres) andANDacross attributes (for example, genre AND language) - Numeric facets include
facetStatswithminandmaxvalues, useful for range sliders
Next steps
Search with facets
Learn more about facets and facet search
Search API reference
Full documentation for the search endpoint parameters
Combine filters and sort
Add sorting to your filtered search results