How query and filter interact
When you send a search request with bothq and filter, Meilisearch applies them in combination:
- Meilisearch finds all documents matching the filter expression
- Within that filtered set, it ranks documents by relevancy to the query
- Facet distributions reflect the intersection of both query and filter
facetDistribution counts change depending on the query. If you search for “running shoes” with a brand facet, you only see brands that have running shoes, not all brands in the index.
Basic example
Start with a products index configured with filterable and searchable attributes:facetDistribution reflects this combined result:
Facet counts are query-aware
This is a key behavior to understand when building search interfaces. Consider two scenarios: Without a query (emptyq):
Combine multiple filters with a query
You can stack filters to narrow results further. Users often select multiple facet values as they refine their search:facetDistribution updates to reflect all active constraints.
Preserve unfiltered facet counts
In some UIs, you want to show all available facet values, even those with zero results under the current query. Meilisearch does not return facet values with zero matches. To show “disabled” facet values in your UI, compare the current facet distribution against a baseline. One approach is to send two requests:- A search request with the current query and all filters, to get active results
- A search request with the current query but without the filter you want to display fully, to get the complete distribution for that facet
limit: 0 in the second request avoids fetching hits when you only need the facet distribution. Use multi-search to send both requests in a single HTTP call.
Use facetStats for range filters
When filtering by numeric attributes like price or rating,facetStats provides the minimum and maximum values. Use these to build range sliders in your UI:
price >= 500 AND price <= 1500 to the next search request.
Next steps
Build faceted navigation
Complete guide to building a faceted search UI
Filter expression reference
Full syntax reference for filter expressions
Multi-search
Send multiple search requests in a single HTTP call