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 .

WARNING

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

GET

Get the distinct attribute field of an index.

Path variables

<>

cURL

JS

Python

PHP

Java

Ruby

Go

Rust

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. print(distinctAttribute)
  4. case .failure(let error):
  5. print(error)
  6. }
  7. }
  1. await client.index('shoes').getDistinctAttribute();

Response: 200 Ok

POST

Update the field of an index.

Path variables

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

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. print(error)
  6. }
  7. }
  1. await client.index('shoes').updateDistinctAttribute('skuid');

Response:

  1. { "updateId": 1 }

This updateId allows you to .

DELETE

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

Default value: null

Path variables

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