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
/indexes/:index_uid/settings/distinct-attribute
Get the distinct attribute field of an index.
Path variables
Variable | Description |
---|---|
index_uid | The index UID |
Example
<>
cURL
JS
Python
PHP
Java
Ruby
Go
Rust
Swift
Dart
curl \
-X GET 'http://localhost:7700/indexes/shoes/settings/distinct-attribute'
client.index('shoes').getDistinctAttribute()
client.index('shoes').get_distinct_attribute()
$client->index('shoes')->getDistinctAttribute();
client.index("shoes").getDistinctAttribute();
client.index('shoes').distinct_attribute
client.Index("shoes").GetDistinctAttribute()
let distinct_attribute: Option<String> = shoes.get_distinct_attribute().await.unwrap();
client.index("shoes").getDistinctAttribute { (result: Result<String, Swift.Error>) in
switch result {
case .success(let distinctAttribute):
print(distinctAttribute)
case .failure(let error):
print(error)
}
}
await client.index('shoes').getDistinctAttribute();
Response: 200 Ok
"skuid"
Update distinct attribute
POST
/indexes/:index_uid/settings/distinct-attribute
Update the distinct attribute field of an index.
Path variables
Variable | Description |
---|---|
index_uid | The 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
curl \
-X POST 'http://localhost:7700/indexes/shoes/settings/distinct-attribute' \
-H 'Content-Type: application/json' \
--data-binary '"skuid"'
client.index('shoes').updateDistinctAttribute('skuid')
client.index('shoes').update_distinct_attribute('skuid')
$client->index('shoes')->updateDistinctAttribute('skuid');
Settings settings = new Settings();
settings.setDistinctAttribute("skuid");
client.index("shoes").updateSettings(settings);
client.index('shoes').update_distinct_attribute('skuid')
client.Index("shoes").UpdateDistinctAttribute("skuid")
let progress: Progress = shoes.set_distinct_attribute("skuid").await.unwrap();
client.index("shoes").updateDistinctAttribute("skuid") { (result: Result<Update, Swift.Error>) in
switch result {
case .success(let update):
print(update)
case .failure(let error):
print(error)
}
}
await client.index('shoes').updateDistinctAttribute('skuid');
Response: 202 Accepted
{ "updateId": 1 }
This updateId
allows you to track the current update.
Reset distinct attribute
DELETE
/indexes/:index_uid/settings/distinct-attribute
Reset the distinct attribute field of an index to its default value.
Default value: null
Path variables
Variable | Description |
---|---|
index_uid | The index UID |
Example
<>
cURL
JS
Python
PHP
Java
Ruby
Go
Rust
Swift
Dart
curl \
-X DELETE 'http://localhost:7700/indexes/shoes/settings/distinct-attribute'
client.index('shoes').resetDistinctAttribute()
client.index('shoes').reset_distinct_attribute()
$client->index('shoes')->resetDistinctAttribute();
//Not yet implemented
client.index('shoes').reset_distinct_attribute
client.Index("shoes").ResetDistinctAttribute()
let progress: Progress = shoes.reset_distinct_attribute().await.unwrap();
client.index("shoes").resetDistinctAttribute { (result: Result<Update, Swift.Error>) in
switch result {
case .success(let update):
print(update)
case .failure(let error):
print(error)
}
}
await client.index('shoes').resetDistinctAttribute();
Response: 202 Accepted
{ "updateId": 1 }
This updateId
allows you to track the current update.