Ranking rules

Child route of the settings route.

Ranking rules are built-in rules that allow you to customize the relevancy of your search results. They are stored in an array and applied in order of appearance.

Ranking rules can also be updated directly through the global settings route along with the other settings.

Learn more about ranking rules.

NOTE

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

Get ranking rules

GET

  1. /indexes/:index_uid/settings/ranking-rules

Get the ranking rules of an index.

Path variables

VariableDescription
index_uidThe index UID

Default value

An array that contains ranking rules in order of importance.

Example

cURL

JavaScript

Python

PHP

Ruby

Go

Rust

  1. curl \
  2. -X GET 'http://localhost:7700/indexes/movies/settings/ranking-rules'
  1. client.index('movies').getRankingRules()
  1. client.index('movies').get_ranking_rules()
  1. $client->index('movies')->getRankingRules();
  1. client.index('movies').ranking_rules
  1. client.Index("movies").GetRankingRules()
  1. let ranking_rules: Vec<String> = movies.get_ranking_rules().await.unwrap();

Response: 200 Ok

List the settings.

  1. [
  2. "words",
  3. "typo",
  4. "proximity",
  5. "attribute",
  6. "exactness",
  7. "desc(release_date)"
  8. ]

Update ranking rules

POST

  1. /indexes/:index_uid/settings/ranking-rules

Update the ranking rules of an index.

Path variables

VariableDescription
index_uidThe index UID

Body

An array that contain ranking rules sorted by order of importance.

To add your own ranking rule, you have to communicate either asc for ascending order or desc for descending order followed by the field name in brackets.

  • To apply an ascending sort (results sorted by increasing value): asc(attribute_name)

  • To apply a descending sort (results sorted by decreasing value): desc(attribute_name)

More information about the body.

Example

cURL

JavaScript

Python

PHP

Ruby

Go

Rust

  1. curl \
  2. -X POST 'http://localhost:7700/indexes/movies/settings/ranking-rules' \
  3. --data '[
  4. "words",
  5. "typo",
  6. "proximity",
  7. "attribute",
  8. "exactness",
  9. "asc(release_date)",
  10. "desc(rank)"
  11. ]'
  1. client.index('movies').updateRankingRules([
  2. 'words',
  3. 'typo',
  4. 'proximity',
  5. 'attribute',
  6. 'exactness',
  7. 'asc(release_date)',
  8. 'desc(rank)'
  9. ])
  1. client.index('movies').update_ranking_rules([
  2. 'words',
  3. 'typo',
  4. 'proximity',
  5. 'attribute',
  6. 'exactness',
  7. 'asc(release_date)',
  8. 'desc(rank)'
  9. ])
  1. $client->index('movies')->updateRankingRules([
  2. 'words',
  3. 'typo',
  4. 'proximity',
  5. 'attribute',
  6. 'exactness',
  7. 'asc(release_date)',
  8. 'desc(rank)'
  9. ]);
  1. client.index('movies').update_ranking_rules([
  2. 'words',
  3. 'typo',
  4. 'proximity',
  5. 'attribute',
  6. 'exactness',
  7. 'asc(release_date)',
  8. 'desc(rank)'
  9. ])
  1. rankingRules := []string{
  2. "words",
  3. "typo",
  4. "proximity",
  5. "attribute",
  6. "exactness",
  7. "asc(release_date)",
  8. "desc(rank)",
  9. }
  10. client.Index("movies").UpdateRankingRules(&rankingRules)
  1. let ranking_rules = [
  2. "words",
  3. "typo",
  4. "proximity",
  5. "attribute",
  6. "exactness",
  7. "asc(release_date)",
  8. "desc(rank)",
  9. ];
  10. let progress: Progress = movies.set_ranking_rules(&ranking_rules).await.unwrap();

Response: 202 Accepted

  1. {
  2. "updateId": 1
  3. }

This updateId allows you to track the current update.

Reset ranking rules

DELETE

  1. /indexes/:index_uid/settings/ranking-rules

Reset the ranking rules of an index to their default value.

TIP

Note that resetting the ranking rules is not the same as removing them.
To remove a ranking rule, use the add or replace ranking rules route.

Default value

An array that contains the built-in ranking rules in the following order:

  1. ["words", "typo", "proximity", "attribute", "exactness"]

Path Variables

VariableDescription
index_uidThe index UID

Example

cURL

JavaScript

Python

PHP

Ruby

Go

Rust

  1. curl \
  2. -X DELETE 'http://localhost:7700/indexes/movies/settings/ranking-rules'
  1. client.index('movies').resetRankingRules()
  1. client.index('movies').reset_ranking_rules()
  1. $client->index('movies')->resetRankingRules();
  1. client.index('movies').reset_ranking_rules
  1. client.Index("movies").ResetRankingRules()
  1. let progress: Progress = movies.reset_ranking_rules().await.unwrap();

Response: 202 Accepted

  1. {
  2. "updateId": 1
  3. }

This updateId allows you to track the current update.