Sortable attributes
Child route of the settings route.
Sortable attributes can also be updated through the global settings route.
Attributes that can be used together with the sort search parameter. To learn more about sortable 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 sortable attributes
GET
/indexes/:index_uid/settings/sortable-attributes
Get an index’s sortableAttributes.
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/books/settings/sortable-attributes'
client.index('books').getSortableAttributes()
client.index('books').get_sortable_attributes()
$client->index('books')->getSortableAttributes();
client.index("books").getSortableAttributes();
client.index('books').sortable_attributes
client.Index("books").GetSortableAttributes()
let sortable_attributes: Vec<String> = books.get_sortable_attributes().await.unwrap();
client.index("books").getSortableAttributes { (result: Result<[String], Swift.Error>) in
switch result {
case .success(let attributes):
print(attributes)
case .failure(let error):
print(error)
}
}
await client.index('books').sortableAttributes();
Response: 200 Ok
List the settings.
[
"price",
"author"
]
Update sortable attributes
POST
/indexes/:index_uid/settings/sortable-attributes
Update an index’s sortable attributes list. This will re-index all documents in the index.
You can read more about sorting at query time on our dedicated guide.
Path variables
Variable | Description |
---|---|
index_uid | The index UID |
Body
An array of strings containing the attributes that can be used to sort search results at query time.
You can read more about this setting at the feature reference page.
Example
<>
cURL
JS
Python
PHP
Java
Ruby
Go
Rust
Swift
Dart
curl \
-X POST 'http://localhost:7700/indexes/books/settings/sortable-attributes' \
-H 'Content-Type: application/json' \
--data-binary '[
"price",
"author"
]'
client.index('books')
.updateSortableAttributes([
'price',
'author'
])
client.index('books').update_sortable_attributes([
'price',
'author'
])
$client->index('books')->updateSortableAttributes([
'price',
'author'
]);
Settings settings = new Settings();
settings.setSortableAttributes(new String[] {"price", "author"});
client.index("books").updateSettings(settings);
client.index('books').update_sortable_attributes([
'price',
'author'
])
sortableAttributes := []string{
"price",
"author",
}
client.Index("books").UpdateSortableAttributes(&sortableAttributes)
let sortable_attributes = [
"price",
"author"
];
let progress: Progress = books.set_sortable_attributes(&sortable_attributes).await.unwrap();
client.index("books").updateSortableAttributes(["price", "author"]) { (result: Result<Update, Swift.Error>) in
switch result {
case .success(let update):
print(update)
case .failure(let error):
print(error)
}
}
await client.index('books').updateSortableAttributes([
'price',
'author'
]);
Response: 202 Accepted
{ "updateId": 1 }
This updateId
allows you to track the current update.
Reset sortable attributes
DELETE
/indexes/:index_uid/settings/sortable-attributes
Reset an index’s sortable attributes list back to its default value.
Default value
An empty array ([]
).
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/books/settings/sortable-attributes'
client.index('books').resetSortableAttributes()
client.index('books').reset_sortable_attributes()
$client->index('books')->resetSortableAttributes();
//Not yet implemented
client.index('books').reset_sortable_attributes
client.Index("books").ResetSortableAttributes()
let progress: Progress = books.reset_sortable_attributes().await.unwrap();
client.index("books").resetSortableAttributes() { (result: Result<Update, Swift.Error>) in
switch result {
case .success(let attributes):
print(attributes)
case .failure(let error):
print(error)
}
}
await client.index('books').resetSortableAttributes();
Response: 202 Accepted
{ "updateId": 1 }
This updateId
allows you to track the current update.