Skip to main content
Faceted navigation displays filter options alongside the number of matching documents, letting users progressively refine their search. This is the pattern behind product sidebars on ecommerce sites, where users can click “Electronics (42)” or “Books (18)” to narrow results. This guide walks through the full pattern: configuring filterable attributes, requesting facet distributions, and building an interactive UI.

Step 1: configure filterable attributes

Only attributes listed in filterableAttributes can be used as facets. Suppose you have a books index with documents like this:
Add the attributes you want as facets to filterableAttributes:
Wait for the settings task to complete before searching.
If an attribute passed to facets has not been added to filterableAttributes, Meilisearch silently ignores it. No error is raised; the attribute simply will not appear in the facetDistribution response. If a facet is missing from your UI, double-check that it is declared as a filterable attribute.

Step 2: request facet distributions

Use the facets search parameter to tell Meilisearch which attributes should include distribution counts in the response:
The response includes a facetDistribution object showing every value for each requested facet and how many documents match:
The 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.
facetStats only considers values stored as JSON numbers. String values are ignored, even when the string contains a numeric value such as "42". If you expect min/max for a given facet and the object is missing, confirm that the underlying field is indexed as a number rather than a string.

Step 3: apply a filter when the user clicks a facet

When a user clicks a facet value, send a new search request with a filter parameter:
The response updates both the 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 using AND and OR operators:
Use 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:
This pattern:
  1. Tracks active filter selections in an activeFilters object
  2. Builds a filter string from active selections on each search
  3. Renders facet values as checkboxes with document counts
  4. Updates both facets and results when the user toggles a checkbox

Tune maxValuesPerFacet

By default, Meilisearch returns up to 100 distinct values per facet in the facetDistribution object. If your UI only displays the top 10 or 20 options, lower maxValuesPerFacet to match what you actually render:
Setting maxValuesPerFacet to a high value might negatively impact performance. Raising it only makes sense when you genuinely need to surface a large number of facet values at once.

Key points

  • Always include the facets parameter in every search request so the sidebar stays updated
  • Facet counts reflect the current filter state, so users see accurate numbers
  • Use OR within the same attribute (for example, multiple genres) and AND across attributes (for example, genre AND language)
  • Numeric facets include facetStats with min and max values, 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