Distinct attribute

Child route of the settings route.

Distinct attribute is a field whose value will always be unique in the returned documents.

Distinct attribute can also be updated directly through the global settings route along with the other settings.

To learn more about distinct attributes, refer to our dedicated guide.

WARNING

Updating the settings means overwriting the default settings of MeiliSearch. You can reset to default values using the DELETE routes.

Get distinct attribute

GET

  1. /indexes/:index_uid/settings/distinct-attribute

Get the distinct attribute field of an index.

Path variables

VariableDescription
index_uidThe index UID

Example

<>

cURL

JS

Python

PHP

Java

Ruby

Go

Rust

Swift

Dart

  1. curl \
  2. -X GET 'http://localhost:7700/indexes/shoes/settings/distinct-attribute'
  1. client.index('shoes').getDistinctAttribute()
  1. client.index('shoes').get_distinct_attribute()
  1. $client->index('shoes')->getDistinctAttribute();
  1. client.index("shoes").getDistinctAttribute();
  1. client.index('shoes').distinct_attribute
  1. client.Index("shoes").GetDistinctAttribute()
  1. let distinct_attribute: Option<String> = shoes.get_distinct_attribute().await.unwrap();
  1. client.index("shoes").getDistinctAttribute { (result: Result<String, Swift.Error>) in
  2. switch result {
  3. case .success(let distinctAttribute):
  4. print(distinctAttribute)
  5. case .failure(let error):
  6. print(error)
  7. }
  8. }
  1. await client.index('shoes').getDistinctAttribute();

Response: 200 Ok

  1. "skuid"

Update distinct attribute

POST

  1. /indexes/:index_uid/settings/distinct-attribute

Update the distinct attribute field of an index.

Path variables

VariableDescription
index_uidThe index UID

Body

A String: the field name.

More information about the body.

WARNING

If the field does not exist, no error will be thrown.

Example

<>

cURL

JS

Python

PHP

Java

Ruby

Go

Rust

Swift

Dart

  1. curl \
  2. -X POST 'http://localhost:7700/indexes/shoes/settings/distinct-attribute' \
  3. -H 'Content-Type: application/json' \
  4. --data-binary '"skuid"'
  1. client.index('shoes').updateDistinctAttribute('skuid')
  1. client.index('shoes').update_distinct_attribute('skuid')
  1. $client->index('shoes')->updateDistinctAttribute('skuid');
  1. Settings settings = new Settings();
  2. settings.setDistinctAttribute("skuid");
  3. client.index("shoes").updateSettings(settings);
  1. client.index('shoes').update_distinct_attribute('skuid')
  1. client.Index("shoes").UpdateDistinctAttribute("skuid")
  1. let progress: Progress = shoes.set_distinct_attribute("skuid").await.unwrap();
  1. client.index("shoes").updateDistinctAttribute("skuid") { (result: Result<Update, Swift.Error>) in
  2. switch result {
  3. case .success(let update):
  4. print(update)
  5. case .failure(let error):
  6. print(error)
  7. }
  8. }
  1. await client.index('shoes').updateDistinctAttribute('skuid');

Response: 202 Accepted

  1. { "updateId": 1 }

This updateId allows you to track the current update.

Reset distinct attribute

DELETE

  1. /indexes/:index_uid/settings/distinct-attribute

Reset the distinct attribute field of an index to its default value.

Default value: null

Path variables

VariableDescription
index_uidThe index UID

Example

<>

cURL

JS

Python

PHP

Java

Ruby

Go

Rust

Swift

Dart

  1. curl \
  2. -X DELETE 'http://localhost:7700/indexes/shoes/settings/distinct-attribute'
  1. client.index('shoes').resetDistinctAttribute()
  1. client.index('shoes').reset_distinct_attribute()
  1. $client->index('shoes')->resetDistinctAttribute();
  1. //Not yet implemented
  1. client.index('shoes').reset_distinct_attribute
  1. client.Index("shoes").ResetDistinctAttribute()
  1. let progress: Progress = shoes.reset_distinct_attribute().await.unwrap();
  1. client.index("shoes").resetDistinctAttribute { (result: Result<Update, Swift.Error>) in
  2. switch result {
  3. case .success(let update):
  4. print(update)
  5. case .failure(let error):
  6. print(error)
  7. }
  8. }
  1. await client.index('shoes').resetDistinctAttribute();

Response: 202 Accepted

  1. { "updateId": 1 }

This updateId allows you to track the current update.