Distinct attribute is a field that prevents Meilisearch from returning a set of several similar documents. Often used in ecommerce datasets where many documents are variations of the same item.
distinctAttribute
index setting during configuration, or the distinct
search parameter at search time.
distinctAttribute
is an index setting that configures a default distinct attribute Meilisearch applies to all searches and facet retrievals in that index.
distinctAttribute
per index. Trying to set multiple fields as a distinctAttribute
will return an error.internal_id
.
lee leather jacket
would return all three documents. This might not be desired, since displaying nearly identical variations of the same item can make results appear cluttered.
In this case, you may want to return only one document with the product_id
corresponding to this Lee jeans leather jacket. To do so, you could set product_id
as the distinctAttribute
.
distinctAttribute
to product_id
, search requests will never return more than one document with the same product_id
.
After setting the distinct attribute as shown above, querying for lee leather jacket
would only return the first document found. The response would look like this:
distinct
is a search parameter you may add to any search query. It allows you to selectively use distinct attributes depending on the context. distinct
takes precedence over distinctAttribute
.
To use an attribute with distinct
, first add it to the filterableAttributes
list:
distinct
in a search query, specifying one of the configured attributes: