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

  1. /indexes/:index_uid/settings/sortable-attributes

Get an index’s sortableAttributes.

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/books/settings/sortable-attributes'
  1. client.index('books').getSortableAttributes()
  1. client.index('books').get_sortable_attributes()
  1. $client->index('books')->getSortableAttributes();
  1. client.index("books").getSortableAttributes();
  1. client.index('books').sortable_attributes
  1. client.Index("books").GetSortableAttributes()
  1. let sortable_attributes: Vec<String> = books.get_sortable_attributes().await.unwrap();
  1. client.index("books").getSortableAttributes { (result: Result<[String], Swift.Error>) in
  2. switch result {
  3. case .success(let attributes):
  4. print(attributes)
  5. case .failure(let error):
  6. print(error)
  7. }
  8. }
  1. await client.index('books').sortableAttributes();

Response: 200 Ok

List the settings.

  1. [
  2. "price",
  3. "author"
  4. ]

Update sortable attributes

POST

  1. /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

VariableDescription
index_uidThe 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

  1. curl \
  2. -X POST 'http://localhost:7700/indexes/books/settings/sortable-attributes' \
  3. -H 'Content-Type: application/json' \
  4. --data-binary '[
  5. "price",
  6. "author"
  7. ]'
  1. client.index('books')
  2. .updateSortableAttributes([
  3. 'price',
  4. 'author'
  5. ])
  1. client.index('books').update_sortable_attributes([
  2. 'price',
  3. 'author'
  4. ])
  1. $client->index('books')->updateSortableAttributes([
  2. 'price',
  3. 'author'
  4. ]);
  1. Settings settings = new Settings();
  2. settings.setSortableAttributes(new String[] {"price", "author"});
  3. client.index("books").updateSettings(settings);
  1. client.index('books').update_sortable_attributes([
  2. 'price',
  3. 'author'
  4. ])
  1. sortableAttributes := []string{
  2. "price",
  3. "author",
  4. }
  5. client.Index("books").UpdateSortableAttributes(&sortableAttributes)
  1. let sortable_attributes = [
  2. "price",
  3. "author"
  4. ];
  5. let progress: Progress = books.set_sortable_attributes(&sortable_attributes).await.unwrap();
  1. client.index("books").updateSortableAttributes(["price", "author"]) { (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('books').updateSortableAttributes([
  2. 'price',
  3. 'author'
  4. ]);

Response: 202 Accepted

  1. { "updateId": 1 }

This updateId allows you to track the current update.

Reset sortable attributes

DELETE

  1. /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

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/books/settings/sortable-attributes'
  1. client.index('books').resetSortableAttributes()
  1. client.index('books').reset_sortable_attributes()
  1. $client->index('books')->resetSortableAttributes();
  1. //Not yet implemented
  1. client.index('books').reset_sortable_attributes
  1. client.Index("books").ResetSortableAttributes()
  1. let progress: Progress = books.reset_sortable_attributes().await.unwrap();
  1. client.index("books").resetSortableAttributes() { (result: Result<Update, Swift.Error>) in
  2. switch result {
  3. case .success(let attributes):
  4. print(attributes)
  5. case .failure(let error):
  6. print(error)
  7. }
  8. }
  1. await client.index('books').resetSortableAttributes();

Response: 202 Accepted

  1. { "updateId": 1 }

This updateId allows you to track the current update.