Skip to main content
The distinct parameter controls how many variants of a record are shown when multiple records share the same value for the attribute defined in attributeForDistinct. This lets you group and deduplicate search results.

Options

false | 0
No grouping or deduplication. All matching records are shown.
This is the default.
true | 1
Returns only the most relevant record from each group. This is useful when you want to show one result per unique product, article, or listing.Only the most relevant variant is shown for each record group.
2 | 3 | 4
Returns the top 2, 3, or 4 records for each group.
  • Avoid grouping with promoted records, as this can lead to wrong nbHits values and broken faceting.
  • When distinct is greater than 1:
    • hitsPerPage controls the number of groups.
    • Up to hitsPerPage × distinct total hits can be returned.
    • The response field nbHits reflects the number of groups, not total records.
Don’t set distinct to values higher than 4, as this significantly reduces search performance.

Usage

  • attributeForDistinct defines how records are grouped.
  • distinct defines how many records per group are shown.
  • If attributeForDistinct is not set, distinct is ignored.
  • To ensure accurate facet counts when distinct is applied, use the afterDistinct modifier when declaring attributesForFaceting.

Example

Current API clients

IndexSettings settings = new IndexSettings();
settings.Distinct = 1;
settings.AttributeForDistinct = "url";

index.SetSettings(settings);
IndexSettings settings = new IndexSettings();
settings.Distinct = 1;
settings.AttributeForDistinct = "url";

index.SetSettings(settings);
I