Skip to main content
Filtering, sorting, and faceting are three complementary tools for refining search results:
  • Filtering narrows results to documents matching specific criteria (e.g., genre = "action")
  • Sorting orders results by a field value (e.g., price ascending)
  • Faceting returns aggregated counts for field values, powering category navigation in your UI

Filters vs facets

Filters and facets both use filterableAttributes, but serve different purposes:
FeaturePurposeExample
FiltersRemove non-matching documents from resultsShow only in-stock items
FacetsShow available options with counts”Color: Red (12), Blue (8)“
SortingOrder results by a fieldCheapest first
Facets are filters that also return distribution data. Use them together to build interactive, ecommerce-style navigation.

How it works

Before you can filter, sort, or facet on an attribute, you must declare it in your index settings. Add attributes to filterableAttributes to enable filtering and faceting, or to sortableAttributes to enable sorting. Meilisearch then builds optimized internal data structures for those attributes, allowing operations to execute quickly even on large datasets. At search time, pass filter expressions in the filter parameter, sorting instructions in the sort parameter, and request facet distributions using the facets parameter. You can combine all three in a single search request.

Common use cases

  • E-commerce faceted navigation: Let shoppers narrow products by brand, color, size, and price range while displaying counts for each option.
  • Date-range filtering: Restrict results to a specific time window, such as articles published in the last 30 days or events happening this week.
  • Price or rating sorting: Allow users to sort results by price (ascending or descending) or by average customer rating.
  • Location-based filtering: Combine geo search filters with category filters to show nearby restaurants, stores, or listings matching specific criteria.

Next steps

Getting started

Set up filterable attributes and run your first filtered search

Faceted navigation

Build category navigation with facet counts

Sorting

Order results by price, date, or any sortable field

Filter syntax

Reference for filter expressions and operators