/facet-search endpoint itself and the edge cases you need to know about before relying on it.
Prerequisites
Before you can search a facet’s values, the attribute must be declared infilterableAttributes. Facet search is enabled by default on every index; you can disable it per index with the facetSearch setting if you do not need it and want to speed up indexing.
Search a facet
Send aPOST request to /indexes/{index_uid}/facet-search with the name of the facet you want to search and the partial string typed by the user:
facetHits array with the matching values and the number of documents that carry each one:
facetQuery with q, filter, and matchingStrategy. See the facet search API reference for the full list of parameters.
Facet search only works on string fields
Internally, Meilisearch stores numbers asfloat64. Floating-point values lack exact decimal precision and can be represented in more than one way, which makes prefix matching on their textual form unreliable. Only string facet values are indexed for facet search.
Facet search only matches the first term of facetQuery
For example, given a author facet that contains "Jane Austen":
facetQuery: "Jane"returnsJane AustenfacetQuery: "Austen"does not returnJane Austen, because the wordAustenis not the start of the stored valuefacetQuery: "Jane Aus"effectively behaves likefacetQuery: "Jane"(the second word is dropped)
q parameter instead and inspect the facetDistribution of the response.
Get exact facet counts
By default, the counts returned by facet search are estimates, which is faster on large indexes. To force exact counts, setexhaustiveFacetCount to true:
Next steps
Search with facets
Configure facets and filter search results
Build faceted navigation
Patterns for category and filter menus
Handle large facet cardinality
Strategies for facets with thousands of values
Facet search API reference
Full list of parameters accepted by
/facet-search