distinct

scope settings search
type integer | boolean
default 0
description

Controls de-duplication of results.

A non-zero value enables de-duplication; a zero value disables it. Booleans are also accepted (though not recommended): false is treated as 0, and true is treated as 1.

De-duplication requires a de-duplication attribute to be configured via the attributeForDistinct index setting. If not configured, distinct will be accepted at query time but silently ignored.

This feature is similar to the SQL distinct keyword. When set to N (where N > 0), at most N hits will be returned with the same value for the de-duplication attribute.

Example: If the de-duplication attribute is show_name and distinct is set to 1, then if several hits have the same value for show_name, only the most relevant one is kept (with respect to the ranking formula); the others are removed.

To get a full understanding of how distinct works, you can have a look at our Guides.

Examples

Set default distinct mode

<?php
$index->setSettings([
  'distinct' => 0
  // 'distinct' => 1
  // 'distinct' => 2
]);
index.set_settings({
  distinct: 0
  # distinct: 1
  # distinct: 2
})
index.setSettings({
  distinct: 0
  // distinct: 1
  // distinct: 2
});
index.set_settings({
    'distinct': 0
    # 'distinct': 1
    # 'distinct': 2
})
index.setSettings([
    "distinct": 0
    // "distinct": 1
    // "distinct": 2
])
index.setSettings(new JSONObject().put("distinct", 10));
index.SetSettings(
  JObject.Parse(@"{""distinct"":""0""}")
  // JObject.Parse(@"{""distinct"":""1""}")
  // JObject.Parse(@"{""distinct"":""2""}")
);
index.setSettings(
  new IndexSettings().setDistinct(Distinct.of(1))
);
res, err := index.SetSettings(algoliasearch.Map{
    "distinct": 0,
    // "distinct": 1,
    // "distinct": 2,
})
client.execute {
  changeSettings of "myIndex" `with` IndexSettings(
    distinct = Some(Distinct.int(0))
    // distinct = Some(Distinct.int(1))
    // distinct = Some(Distinct.int(2))
  )
}
<?php
$results = $index->search('query', [
  'distinct' => 0
  // 'distinct' => 1
  // 'distinct' => 2
]);
results = index.search('query', {
  distinct: 0
  # distinct: 1
  # distinct: 2
})
index.search({
  query: 'query',
  distinct: 0
  // 'distinct: 1
  // 'distinct: 2
}).then(res => {
  // console.log(res);
});
results = index.search('query', {
    'distinct': 0
    # 'distinct': 1
    # 'distinct': 2
})
let query = Query(query: "query")
query.distinct = 0
// query.distinct = 1
// query.distinct = 2

index.search(query, completionHandler: { (res, error) in
    print(res)
})
index.search(new Query("query").setDistinct(10));
index.search(
  new Query("query").AddCustomParameter("distinct", "0")
  // new Query("query").AddCustomParameter("distinct", "1")
  // new Query("query").AddCustomParameter("distinct", "2")
);
index.search(
  new Query("query").setDistinct(0)
  // new Query("query").setDistinct(1)
  // new Query("query").setDistinct(2)
);
res, err := index.Search("query", algoliasearch.Map{
    "distinct": 0,
    // "distinct": 1,
    // "distinct": 2,
})
client.execute {
  search into "myIndex" query Query(
    query = Some("query"),
    distinct = Some(Distinct.int(0))
    // distinct = Some(Distinct.int(1))
    // distinct = Some(Distinct.int(2))
  )
}
Php small white
PHP
Ruby small white
Ruby
Javascript small white
JavaScript
Python small white
Python
Swift small white
iOS
Android small white
Android
Csharp small white
C#
Java small white
Java
Go small white
Go
Scala small white
Scala
Php small white
PHP
Ruby small white
Ruby
Javascript small white
JavaScript
Python small white
Python
Swift small white
iOS
Android small white
Android
Csharp small white
C#
Java small white
Java
Go small white
Go
Scala small white
Scala