Requirements
- a Meilisearch project
- a command-line terminal
Configure facet index settings
First, create a new index using this books dataset. Documents in this dataset have the following fields:genres, language, and rating to the list of filterableAttributes:
Use facets in a search query
Make a search query setting thefacets search parameter:
facetDistribution and facetStats:
facetDistribution lists all facets present in your search results, along with the number of documents returned for each facet.
facetStats contains the highest and lowest values for all facets containing numeric values.
Sorting facet values
By default, all facet values are sorted in ascending alphanumeric order. You can change this using thesortFacetValuesBy property of the faceting index settings:
genres facet by descending value count.
Repeating the previous query using the new settings will result in a different order in facetsDistribution:
Searching facet values
You can also search for facet values with the facet search endpoint:genres facet for values starting with c:
The response contains a facetHits array listing all matching facets, together with the total number of documents that include that facet:
q, filter, and matchingStrategy parameters. Learn more about them in the API reference.