Distinct
With theattributeForDistinct setting,
you define an attribute for the deduplication.
For example, if you set the url attribute as attributeForDistinct,
then Algolia treats all records with the same URL as variants of each other.
You can then control how many variants should be included in the search results
with the distinct parameter.
If you want to define groups of records, based on queries, or matching filters,
see Smart Groups.
Flatten your records
To effectively usedistinct and attributeForDistinct,
you need to flatten your records.
The following example illustrates the difference between nested and flat record structures
and their implications for search.
Before—nested
With a nested approach, your records might look like this:JSON
After—flat
Instead of nesting, create one record for each opening, and repeat the company each time:JSON
Configure distinct in the dashboard
To select an attribute for deduplication:- Go to the Algolia dashboard and select your Algolia application.
- On the left sidebar, select Search.
- Select your Algolia index.
- On the Configuration tab, select Search behavior > Deduplication and Grouping.
- In the Distinct menu, select “true”.
- In the Attribute for Distinct menu, select “company”.
Configure distinct with the API
Use thesetSettings method with the attributeForDistinct parameter
and the company attribute.
Optional: set distinct to true using the same method.
This deduplicates all following search requests.
attributeForDistinct,
you can set distinct as an additional parameter to the search methods:
Handle item variations
For example, consider a shop that sells t-shirts and sweatshirts in different designs and colors. To make them searchable, you can structure your records in these ways:- One record for each product: product-level model
- One record for each color variant: variant-level model
One record per variant
The inventory has:- 2 t-shirt designs: A and B
- 2 sweatshirt designs: C and D

JSON
JSON
number_of_sales.
Again, you can also use distinct to limit the number of variants shown per design.
This lets users explore more of your designs instead of all variations of a single design.
Configure distinct in the dashboard
- Go to the Algolia dashboard and select your Algolia application.
- On the left sidebar, select Search.
- Select your Algolia index.
- On the Configuration tab, select Relevance essentials > Searchable attributes.
- Click Add a Searchable Attribute and add
design,type, andcolorattributes. - Go to Search behavior > Deduplication and Grouping.
- In the Distinct menu, select “true”.
- In the Attribute for Distinct menu, select “design”.
number_of_sales and use it as custom ranking.

Configure distinct with the API
Before deduplicating items, restrict what should be searchable. For example, searching within thethumbnail_url attribute might lead to irrelevant noise.
The attribute color_variants is added for UI purposes only and could lead to false positive matches.
Therefore, only set design, type, and color as searchableAttributes.
design as attributeForDistinct.
Optional: set distinct to true.
This deduplicates all following search requests.
attributeForDistinct,
you can set distinct as an additional parameter to the search methods: