Settings

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

VariableDescriptionDefault value
displayedAttributesFields displayed in the returned documentsAll attributes found in the documents
distinctAttributeSearch returns documents with distinct (different) values of the given fieldnull
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
searchableAttributesFields in which to search for matching query words sorted by order of importanceAll attributes found in the documents
sortableAttributes[Strings]Attributes to use when sorting search results
stopWordsList of words ignored by MeiliSearch when present in search queries[]
synonymsList of associated words treated similarly{}

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

JS

Python

PHP

Java

Ruby

Go

Rust

Swift

Dart

  1. curl \
  2. -X POST 'http://localhost:7700/indexes/movies/settings' \
  3. -H 'Content-Type: application/json' \
  4. --data-binary '{
  5. "displayedAttributes": [
  6. "title",
  7. "description",
  8. "genre",
  9. "release_date"
  10. ]
  11. }'
  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. Settings settings = new Settings();
  2. settings.setDisplayedAttributes(new String[]
  3. {
  4. "title",
  5. "description",
  6. "genre",
  7. "release_date"
  8. });
  9. client.index("movies").updateSettings(settings);
  1. client.index('movies').update_settings({
  2. displayed_attributes: [
  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();
  1. let displayedAttributes: [String] = [
  2. "title",
  3. "description",
  4. "poster",
  5. "release_date",
  6. "rank"
  7. ]
  8. client.index("movies").updateDisplayedAttributes(displayedAttributes) { (result: Result<Update, Swift.Error>) in
  9. switch result {
  10. case .success(let update):
  11. print(update)
  12. case .failure(let error):
  13. print(error)
  14. }
  15. }
  1. await client.index('movies').updateSettings(IndexSettings(
  2. displayedAttributes: ['title', 'description', 'genre', 'release_date']));

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

JS

Python

PHP

Java

Ruby

Go

Rust

Swift

Dart

  1. curl \
  2. -X POST 'http://localhost:7700/indexes/jackets/settings' \
  3. -H 'Content-Type: application/json' \
  4. --data-binary '{
  5. "distinctAttribute": "product_id"
  6. }
  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. Settings settings = new Settings();
  2. settings.setDistinctAttribute("product_id");
  3. client.index("jackets").updateSettings(settings);
  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();
  1. client.index("movies").updateDistinctAttribute("product_id") { (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
  2. .index('jackets')
  3. .updateSettings(IndexSettings(distinctAttribute: 'product_id'));

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

Filterable attributes

List of attributes 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

JS

Python

PHP

Java

Ruby

Go

Rust

Swift

Dart

  1. curl \
  2. -X POST 'http://localhost:7700/indexes/movies/settings' \
  3. -H 'Content-Type: application/json' \
  4. --data-binary '{
  5. "filterableAttributes": [
  6. "director",
  7. "genres"
  8. ]
  9. }'
  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. Settings settings = new Settings();
  2. settings.setFilterableAttributes(new String[] {"director", "genres"});
  3. client.index("movies").updateSettings(settings);
  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();
  1. client.index("movies").updateFilterableAttributes(["genre", "director"]) { (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('movies').updateFilterableAttributes([
  2. 'director',
  3. 'genres',
  4. ]);

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. [
  2. "words",
  3. "typo",
  4. "proximity",
  5. "attribute",
  6. "sort",
  7. "exactness"
  8. ]

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

JS

Python

PHP

Java

Ruby

Go

Rust

Swift

Dart

  1. curl \
  2. -X POST 'http://localhost:7700/indexes/movies/settings' \
  3. -H 'Content-Type: application/json' \
  4. --data-binary '{
  5. "rankingRules": [
  6. "words",
  7. "typo",
  8. "proximity",
  9. "attribute",
  10. "sort",
  11. "exactness",
  12. "release_date:asc",
  13. "rank:desc"
  14. ]
  15. }'
  1. client.index('movies').updateSettings({
  2. rankingRules: [
  3. 'words',
  4. 'typo',
  5. 'proximity',
  6. 'attribute',
  7. 'sort',
  8. 'exactness',
  9. 'release_date:asc',
  10. 'rank:desc'
  11. ]
  12. })
  1. client.index('movies').update_settings({
  2. 'rankingRules': [
  3. 'words',
  4. 'typo',
  5. 'proximity',
  6. 'attribute',
  7. 'sort',
  8. 'exactness',
  9. 'release_date:asc',
  10. 'rank:desc'
  11. ]
  12. })
  1. $client->index('movies')->updateRankingRules([
  2. 'words',
  3. 'typo',
  4. 'proximity',
  5. 'attribute',
  6. 'sort',
  7. 'exactness',
  8. 'release_date:asc',
  9. 'rank:desc'
  10. ]);
  1. Settings settings = new Settings();
  2. settings.setRankingRules(new String[]
  3. {
  4. "words",
  5. "typo",
  6. "proximity",
  7. "attribute",
  8. "sort",
  9. "exactness",
  10. "release_date:asc",
  11. "rank_desc"
  12. });
  13. client.index("movies").updateSettings(settings);
  1. client.index('movies').update_settings({
  2. ranking_rules: [
  3. 'words',
  4. 'typo',
  5. 'proximity',
  6. 'attribute',
  7. 'sort',
  8. 'exactness',
  9. 'release_date:asc',
  10. 'rank:desc'
  11. ]
  12. })
  1. rankingRules := []string{
  2. "words",
  3. "typo",
  4. "proximity",
  5. "attribute",
  6. "sort",
  7. "exactness",
  8. "release_date:asc",
  9. "rank:desc",
  10. }
  11. client.Index("movies").UpdateRankingRules(&rankingRules)
  1. let ranking_rules = [
  2. "words",
  3. "typo",
  4. "proximity",
  5. "attribute",
  6. "sort",
  7. "exactness",
  8. "release_date:asc",
  9. "rank:desc",
  10. ];
  11. let progress: Progress = movies.set_ranking_rules(&ranking_rules).await.unwrap();
  1. let rankingRules: [String] = [
  2. "words",
  3. "typo",
  4. "proximity",
  5. "attribute",
  6. "sort",
  7. "exactness",
  8. "release_date:asc",
  9. "rank:desc"
  10. ]
  11. client.index("movies").updateRankingRules(rankingRules) { (result: Result<Update, Swift.Error>) in
  12. switch result {
  13. case .success(let update):
  14. print(update)
  15. case .failure(let error):
  16. print(error)
  17. }
  18. }
  1. await client.index('movies').updateSettings(IndexSettings(rankingRules: [
  2. 'words',
  3. 'typo',
  4. 'proximity',
  5. 'attribute',
  6. 'sort',
  7. 'exactness',
  8. 'release_date:asc',
  9. 'rank:desc'
  10. ]));

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).

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

JS

Python

PHP

Java

Ruby

Go

Rust

Swift

Dart

  1. curl \
  2. -X POST 'http://localhost:7700/indexes/movies/settings' \
  3. -H 'Content-Type: application/json' \
  4. --data-binary '{
  5. "searchableAttributes": [
  6. "title",
  7. "description",
  8. "genre"
  9. ]
  10. }'
  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. Settings settings = new Settings();
  2. settings.setSearchableAttributes(new String[]
  3. {
  4. "title",
  5. "description",
  6. "genre"
  7. });
  8. client.index("movies").updateSettings(settings);
  1. client.index('movies').update_settings({
  2. searchable_attributes: [
  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();
  1. let searchableAttributes: [String] = [
  2. "uid",
  3. "movie_id",
  4. "title",
  5. "description",
  6. "poster",
  7. "release_date",
  8. "rank"
  9. ]
  10. client.index("movies").updateSearchableAttributes(searchableAttributes) { (result: Result<Update, Swift.Error>) in
  11. switch result {
  12. case .success(let update):
  13. print(update)
  14. case .failure(let error):
  15. print(error)
  16. }
  17. }
  1. await client.index('movies').updateSettings(
  2. IndexSettings(searchableAttributes: ['title', 'description', 'genre']));

Sortable attributes

List of attributes that can be used for sorting.

By default, sortableAttributes 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 sortableAttributes is necessary in order to use the sort search parameter.

Learn more about sorting in our dedicated guide.

Example

To be able to sort search results according to the attributes price and author in a webshop, you must first add them to the sortableAttributes list:

No example found

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

JS

Python

PHP

Java

Ruby

Go

Rust

Swift

Dart

  1. curl \
  2. -X POST 'http://localhost:7700/indexes/movies/settings' \
  3. -H 'Content-Type: application/json' \
  4. --data-binary '{
  5. "stopWords": [
  6. "the",
  7. "a",
  8. "an"
  9. ]
  10. }'
  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. Settings settings = new Settings();
  2. settings.setStopWords(new String[]
  3. {
  4. "the",
  5. "a",
  6. "an"
  7. });
  8. client.index("movies").updateSettings(settings);
  1. client.index('movies').update_settings({
  2. stop_words: [
  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();
  1. let stopWords: [String] = [
  2. "the",
  3. "a",
  4. "an"
  5. ]
  6. client.index("movies").updateStopWords(stopWords) { (result: Result<Update, Swift.Error>) in
  7. switch result {
  8. case .success(let update):
  9. print(update)
  10. case .failure(let error):
  11. print(error)
  12. }
  13. }
  1. await client
  2. .index('movies')
  3. .updateSettings(IndexSettings(stopWords: ['the', 'a', 'an']));

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.

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

JS

Python

PHP

Java

Ruby

Go

Rust

Swift

Dart

  1. curl \
  2. -X POST 'http://localhost:7700/indexes/tops/settings' \
  3. -H 'Content-Type: application/json' \
  4. --data-binary '{
  5. "synonyms": {
  6. "sweater": ["jumper"],
  7. "jumper": ["sweater"]
  8. }
  9. }'
  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. HashMap<String, String[]> synonyms = new HashMap<String, String[]>();
  2. synonyms.put("sweater", new String[] {"jumper"});
  3. synonyms.put("jumper", new String[] {"sweater"});
  4. settings.setSynonyms(synonyms);
  5. client.index("movies").updateSynonyms(synonyms);
  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();
  1. let synonyms: [String: [String]] = [
  2. "sweater": ["jumper"],
  3. "jumper": ["sweater"]
  4. ]
  5. client.index("tops").updateSynonyms(synonyms) { (result: Result<Update, Swift.Error>) in
  6. switch result {
  7. case .success(let update):
  8. print(update)
  9. case .failure(let error):
  10. print(error)
  11. }
  12. }
  1. await client.index('tops').updateSettings(IndexSettings(synonyms: {
  2. 'sweater': ['jumper'],
  3. 'jumper': ['sweater']
  4. }));

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