Settings

This page describes all the settings available in MeiliSearch and how to configure them.

VariableDescriptionDefault value
synonymsList of associated words treated similarly{}
stopWordsList of words ignored by MeiliSearch when present in search queries[]
filterableAttributesList of attributes that can be used for filteringnull
rankingRulesList of ranking rules sorted by order of importanceA list of ordered built-in ranking rules
distinctAttributeSearch returns documents with distinct (different) values of the given fieldnull
searchableAttributesFields in which to search for matching query words sorted by order of importanceAll attributes found in the documents
displayedAttributesFields displayed in the returned documentsAll attributes found in the documents

Synonyms

A set of words defined for an index. Synonyms are different words that have the same meaning, and thus are treated similarly. If either of the associated words is searched, the same results will be displayed.

synonyms=<Object>

  • <Object> (Object, defaults to {}) : { <String>: [<String>, <String>, ...], ... }

    An object that contains words with a list of their associated synonyms. Synonym strings are normalized.

Learn more about synonyms

Example

Suppose you have an e-commerce dataset. For an index that contains information about tops, you decide to create synonyms for sweater and jumper since these two items are very similar.

cURL

JavaScript

Python

PHP

Ruby

Go

Rust

  1. curl \
  2. -X POST 'http://localhost:7700/indexes/tops/settings' \
  3. --data '{
  4. "synonyms": {
  5. "sweater": ["jumper"],
  6. "jumper": ["sweater"]
  7. }
  8. }'
  1. client.index('tops').updateSettings({
  2. synonyms: {
  3. sweater: ['jumper'],
  4. jumper: ['sweater']
  5. })
  1. client.index('tops').update_settings({
  2. 'synonyms': {
  3. sweater: ['jumper'],
  4. jumper: ['sweater']
  5. },
  6. })
  1. $client->index('tops')->updateSynonyms(['sweater' => ['jumper'], 'jumper' => ['sweater']]);
  1. client.index('tops').update_settings({
  2. synonyms: {
  3. sweater: ['jumper'],
  4. jumper: ['sweater']
  5. }
  6. })
  1. synonyms := map[string][]string{
  2. "sweater": []string{"jumper"},
  3. "jumper": []string{"sweater"},
  4. }
  5. client.Index("tops").UpdateSynonyms(&synonyms)
  1. let mut synonyms = HashMap::new();
  2. synonyms.insert(String::from("sweater"), vec![String::from("jumper")]);
  3. synonyms.insert(String::from("jumper"), vec![String::from("sweater")]);
  4. let tops: Index = client.get_index("tops").await.unwrap();
  5. let progress: Progress = tops.set_synonyms(&synonyms).await.unwrap();

By doing so, when searching for black sweater, results for black jumper will also be returned.

Stop words

A set of words defined for an index. Because some words neither add semantic value nor context, you may want to ignore them from your search. Stop words are ignored during search.

stopWords=[<String>, <String>, ...]

  • [<String>, <String>, ...] (Array of strings, defaults to [])

    An array of strings that contains the stop words.

Learn more about stop words

Example

To add the, a and an to the stop words list, send:

cURL

JavaScript

Python

PHP

Ruby

Go

Rust

  1. curl \
  2. -X POST 'http://localhost:7700/indexes/movies/settings' \
  3. --data '{
  4. "stopWords": [
  5. "the",
  6. "a",
  7. "an"
  8. ]
  9. }'
  1. client.index('movies').updateSettings({
  2. stopWords: [
  3. 'the',
  4. 'a',
  5. 'an'
  6. ]
  7. })
  1. client.index('movies').update_settings({
  2. 'stopWords': [
  3. 'the',
  4. 'a',
  5. 'an'
  6. ],
  7. })
  1. $client->index('movies')->updateStopWords(['the', 'a', 'an']);
  1. client.index('movies').update_settings({
  2. stopWords: [
  3. 'the',
  4. 'a',
  5. 'an'
  6. ]
  7. })
  1. stopWords := []string{"the", "a", "an"}
  2. client.Index("movies").UpdateStopWords(&stopWords)
  1. let progress: Progress = movies.set_stop_words(["the", "a", "an"]).await.unwrap();

With the settings in the example above, the, a and an are now ignored by the sorting algorithm if they are present in search queries.

Suppose you would like to search the mask in a movie database. Since the is ignored during search, MeiliSearch will look for every movie containing mask and not the millions ones containing the. the is a less relevant term than mask and also a very frequent word in English. By adding the to the stop words list, MeiliSearch will ignore this word, and thus be faster to answer without losing in relevancy.

Filterable attributes

List of attributes

An attribute is the name of a field, like a key.

Ex: "title": "Batman"
In the example above, “title” is the attribute.

that can be used for filtering and faceted search.

By default, filterableAttributes is an empty array. It expects an array of attributes whose corresponding values are either numbers or strings. null fields or fields that contain empty arrays are silently ignored, but an error will be thrown if the field’s value is an object.

TIP

Configuring filterableAttributes is necessary in order to use the filter search parameter.

Learn more about filtering and faceted search in our dedicated guide.

Example

To be able to filter search results on director and genres in a movie database, you must first add these attributes to the filterableAttributes list:

cURL

JavaScript

Python

PHP

Ruby

Go

Rust

  1. curl \
  2. -X POST 'http://localhost:7700/indexes/movies/settings' \
  3. --data '{
  4. "filterableAttributes": [
  5. "director",
  6. "genres"
  7. ]
  8. }'
  1. client.index('movies')
  2. .updateFilterableAttributes([
  3. 'director',
  4. 'genres'
  5. ])
  1. client.index('movies').update_filterable_attributes([
  2. 'director',
  3. 'genres',
  4. ])
  1. $client->index('movies')->updateFilterableAttributes(['director', 'genres']);
  1. client.index('movies').update_filterable_attributes([
  2. 'director',
  3. 'genres'
  4. ])
  1. resp, err := client.Index("movies").UpdateFilterableAttributes(&[]string{
  2. "director",
  3. "genres",
  4. })
  1. let progress: Progress = movies.set_filterable_attributes(["director", "genres"]).await.unwrap();

Ranking rules

Built-in ranking rules that ensure relevancy in search results. Ranking rules are applied in a default order which can be changed in the settings. You can add or remove rules and change their order of importance.

rankingRules=[<String>, <String>, ...]

  • [<String>, <String>, ...] (Array of strings, see default value below)

    An array of strings that contains the ranking rules sorted by order of importance (arranged from the most important rule to the least important rule).

Default value (the ranking rules in the default order):

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

Read this guide to know more about what each ranking rules does

Custom ranking rule

You can add a custom ranking rule anywhere in the list of ranking rules. A custom ranking rule is composed of an attribute and an ascending or descending order. The attribute must have a numeric value in the documents.

WARNING

If some documents do not contain the attribute defined in a custom ranking rule, the application of the ranking rule is undefined and the search results might not be sorted as you expected.

We recommend that all your documents contain any attribute used in a custom ranking rule. For example, if you set the custom ranking rule desc(year), make sure that all your documents contain the attribute year.

Example

To add your ranking rules to the settings, send:

cURL

JavaScript

Python

PHP

Ruby

Go

Rust

  1. curl \
  2. -X POST 'http://localhost:7700/indexes/movies/settings' \
  3. --data '{
  4. "rankingRules": [
  5. "words",
  6. "typo",
  7. "proximity",
  8. "attribute",
  9. "exactness",
  10. "asc(release_date)",
  11. "desc(rank)"
  12. ]
  13. }'
  1. client.index('movies').updateSettings({
  2. rankingRules: [
  3. 'words',
  4. 'typo',
  5. 'proximity',
  6. 'attribute',
  7. 'exactness',
  8. 'asc(release_date)',
  9. 'desc(rank)'
  10. ]
  11. })
  1. client.index('movies').update_settings({
  2. 'rankingRules': [
  3. 'words',
  4. 'typo',
  5. 'proximity',
  6. 'attribute',
  7. 'exactness',
  8. 'asc(release_date)',
  9. 'desc(rank)'
  10. ]
  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_settings({
  2. rankingRules: [
  3. 'words',
  4. 'typo',
  5. 'proximity',
  6. 'attribute',
  7. 'exactness',
  8. 'asc(release_date)',
  9. 'desc(rank)'
  10. ]
  11. })
  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();

With the settings in the example above, documents will be sorted by number of typos first. If too many documents have the same number of typos, the words rule will be applied. This operation will be repeated with the next rules until the requested number of documents has been reached (default: 20).

Distinct attribute

The value of a field whose attribute is set as a distinct attribute will always be unique in the returned documents.

distinctAttribute=<String>

  • <String> (String, defaults to null)

    The field name.

Learn more about the distinct attribute

Example

Suppose you have an e-commerce dataset. For an index that contains information about jackets, you may have several identical items in different variations (color or size).

As shown below, you have 2 documents that contain information about the same jacket. One of the jackets is brown and the other one is black.

  1. [
  2. {
  3. "id": 1,
  4. "description": "Leather jacket",
  5. "brand": "Lee jeans",
  6. "color": "brown",
  7. "product_id": "123456"
  8. },
  9. {
  10. "id": 2,
  11. "description": "Leather jacket",
  12. "brand": "Lee jeans",
  13. "color": "black",
  14. "product_id": "123456"
  15. }
  16. ]

You may want to ignore the different colors of an item. To do so, you can set product_id as a distinctAttribute.

cURL

JavaScript

Python

PHP

Ruby

Go

Rust

  1. curl \
  2. -X POST 'http://localhost:7700/indexes/jackets/settings' \
  3. --data '{
  4. "distinctAttribute": "product_id"
  5. }
  1. client.index('movies').updateSettings({
  2. distinctAttribute: 'product_id'
  3. })
  1. client.index('jackets').update_settings({
  2. 'distinctAttribute': 'product_id'
  3. })
  1. $client->index('jackets')->updateDistinctAttribute('product_id');
  1. client.index('jackets').update_distinct_attribute('product_id')
  1. client.Index("jackets").UpdateDistinctAttribute("product_id")
  1. let jackets: Index = client.get_index("jackets").await.unwrap();
  2. let progress: Progress = jackets.set_distinct_attribute("product_id").await.unwrap();

With the settings in the example above, only one of the two documents will be returned if you search Lee leather jacket.

Searchable attributes

The content of the fields whose attributes are added to the searchable-attributes list are searched for matching query words.

searchableAttributes=[<String>, <String>, ...]

  • [<String>, <String>, ...] (Array of strings, defaults to all attributes found in the documents)

    An array of strings that contains searchable attributes ordered by importance (arranged from the most important attribute to the least important attribute).

Learn more about searchable attributes

Example

By adding the following settings, the fields title, description and genre will be searched.

cURL

JavaScript

Python

PHP

Ruby

Go

Rust

  1. curl \
  2. -X POST 'http://localhost:7700/indexes/movies/settings' \
  3. --data '{
  4. "searchableAttributes": [
  5. "title",
  6. "description",
  7. "genre"
  8. ]
  9. }'
  1. client.index('movies').updateSettings({
  2. searchableAttributes: [
  3. 'title',
  4. 'description',
  5. 'genre'
  6. ]
  7. })
  1. client.index('movies').update_settings({
  2. 'searchableAttributes': [
  3. 'title',
  4. 'description',
  5. 'genre'
  6. ]
  7. })
  1. $client->index('movies')->updateSearchableAttributes([
  2. 'title',
  3. 'description',
  4. 'genre'
  5. ]);
  1. client.index('movies').update_settings({
  2. searchableAttributes: [
  3. 'title',
  4. 'description',
  5. 'genre'
  6. ]
  7. })
  1. searchableAttributes := []string{
  2. "title",
  3. "description",
  4. "genre",
  5. }
  6. client.Index("movies").UpdateSearchableAttributes(&searchableAttributes)
  1. let searchable_attributes = [
  2. "title",
  3. "description",
  4. "genre"
  5. ];
  6. let progress: Progress = movies.set_searchable_attributes(&searchable_attributes).await.unwrap();

Displayed attributes

The fields whose attributes are added to the displayed-attributes list are contained in each matching document.

Documents returned upon search contain only displayed fields.

displayedAttributes=[<String>, <String>, ...]

  • [<String>, <String>, ...] (Array of strings, defaults to all attributes found in the documents)

    An array of strings that contains attributes of an index to display.

Learn more about displayed attributes

Example

By adding the following settings, documents returned upon search will contain the fields title, description, genre and release_date.

cURL

JavaScript

Python

PHP

Ruby

Go

Rust

  1. curl \
  2. -X POST 'http://localhost:7700/indexes/movies/settings' \
  3. --data '{
  4. "displayedAttributes": [
  5. "title",
  6. "description",
  7. "genre",
  8. "release_date"
  9. ]
  10. }'
  1. client.index('movies').updateSettings({
  2. displayedAttributes: [
  3. 'title',
  4. 'description',
  5. 'genre',
  6. 'release_date',
  7. ]
  8. })
  1. client.index('movies').update_settings({
  2. 'displayedAttributes': [
  3. 'title',
  4. 'description',
  5. 'genre',
  6. 'release_date'
  7. ]
  8. })
  1. $client->index('movies')->updateDisplayedAttributes([
  2. 'title',
  3. 'description',
  4. 'genre',
  5. 'release_date'
  6. ]);
  1. client.index('movies').update_settings({
  2. displayedAttributes: [
  3. 'title',
  4. 'description',
  5. 'genre',
  6. 'release_date'
  7. ]
  8. })
  1. displayedAttributes := []string{
  2. "title",
  3. "description",
  4. "genre",
  5. "release_date",
  6. }
  7. client.Index("movies").UpdateDisplayedAttributes(&displayedAttributes)
  1. let displayed_attributes = [
  2. "title",
  3. "description",
  4. "genre",
  5. "release_date"
  6. ];
  7. let progress: Progress = movies.set_displayed_attributes(&displayed_attributes).await.unwrap();