Settings
This page describes all the settings available in MeiliSearch and how to configure them.
Variable | Description | Default value |
---|---|---|
synonyms | List of associated words treated similarly | {} |
stopWords | List of words ignored by MeiliSearch when present in search queries | [] |
attributesForFaceting | Attributes to use as facets | null |
rankingRules | List of ranking rules sorted by order of importance | A list of ordered built-in ranking rules |
distinctAttribute | Search returns documents with distinct (different) values of the given field | null |
searchableAttributes | Fields in which to search for matching query words sorted by order of importance | All attributes found in the documents |
displayedAttributes | Fields displayed in the returned documents | All 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.
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 \
-X POST 'http://localhost:7700/indexes/tops/settings' \
--data '{
"synonyms": {
"sweater": ["jumper"],
"jumper": ["sweater"]
}
}'
client.index('tops').updateSettings({
synonyms: {
sweater: ['jumper'],
jumper: ['sweater']
})
client.index('movies').update_settings({
'synonyms': {
sweater: ['jumper'],
jumper: ['sweater']
},
})
$client->index('tops')->updateSynonyms(['sweater' => ['jumper'], 'jumper' => ['sweater']]);
index.update_settings({
synonyms: {
sweater: ['jumper'],
jumper: ['sweater']
}
})
synonyms := map[string][]string{
"sweater": []string{"jumper"},
"jumper": []string{"sweater"},
}
client.Settings("tops").UpdateSynonyms(synonyms)
let mut synonyms = HashMap::new();
synonyms.insert(String::from("sweater"), vec![String::from("jumper")]);
synonyms.insert(String::from("jumper"), vec![String::from("sweater")]);
let tops: Index = client.get_index("tops").await.unwrap();
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.
Example
To add the
, a
and an
to the stop words list, send:
$ curl \
-X POST 'http://localhost:7700/indexes/movies/settings' \
--data '{
"stopWords": [
"the",
"a",
"an"
]
}'
client.index('movies').updateSettings({
stopWords: [
'the',
'a',
'an'
]
})
client.index('movies').update_settings({
'stopWords': [
'the',
'a',
'an'
],
})
$client->index('movies')->updateStopWords(['the', 'a', 'an']);
index.update_settings({
stopWords: [
'the',
'a',
'an'
]
})
stopWords := []string{"the", "a", "an"}
client.Settings("movies").UpdateStopWords(stopWords)
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.
Attributes For Faceting
Faceted are the attributes used as facets. They must be added to the settings to be usable as facet filters.
attributesForFaceting=[<Attribute>, ...]
[<Attribute>, ...]
(Array of strings, defaults tonull
)An array of strings that contains the attributes to use as facets.
WARNING
Only fields of data type string or array of strings can be used for faceting.
A null
value will be ignored. In any other case, an error will be thrown.
Learn more about faceted attributes
Example
To be able to facet search on director
and genres
in a movie database, you would declare faceted attributes as follows:
$ curl \
-X POST 'http://localhost:7700/indexes/movies/settings' \
--data '{
"attributesForFaceting": [
"director",
"genres"
]
}'
client.index('movies')
.updateAttributesForFaceting([
'director',
'genres'
])
client.index('movies').update_attributes_for_faceting([
'director',
'genres',
])
$client->index('movies')->updateAttributesForFaceting(['director', 'genres']);
index.update_attributes_for_faceting([
'director',
'genres'
])
response, error := client.Settings("movies").UpdateAttributesForFaceting([]string{
"director",
"genres",
})
let progress: Progress = movies.set_attributes_for_faceting(&["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):
["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.
Example
To add your ranking rules to the settings, send:
$ curl \
-X POST 'http://localhost:7700/indexes/movies/settings' \
--data '{
"rankingRules": [
"typo",
"words",
"proximity",
"attribute",
"wordsPosition",
"exactness",
"asc(release_date)",
"desc(rank)"
]
}'
client.index('movies').updateSettings({
rankingRules: [
'typo',
'words',
'proximity',
'attribute',
'wordsPosition',
'exactness',
'asc(release_date)',
'desc(rank)'
]
})
client.index('movies').update_settings({
'rankingRules': [
'typo',
'words',
'proximity',
'attribute',
'wordsPosition',
'exactness',
'asc(release_date)',
'desc(rank)'
]
})
$client->index('movies')->updateRankingRules([
'typo',
'words',
'proximity',
'attribute',
'wordsPosition',
'exactness',
'asc(release_date)',
'desc(rank)'
]);
index.update_settings({
rankingRules: [
'typo',
'words',
'proximity',
'attribute',
'wordsPosition',
'exactness',
'asc(release_date)',
'desc(rank)'
]
})
rankingRules := []string{
"typo",
"words",
"proximity",
"attribute",
"wordsPosition",
"exactness",
"asc(release_date)",
"desc(rank)",
}
client.Settings("movies").UpdateRankingRules(rankingRules)
let ranking_rules = &[
"typo",
"words",
"proximity",
"attribute",
"wordsPosition",
"exactness",
"asc(release_date)",
"desc(rank)",
];
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 tonull
)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.
[
{
"id": 1,
"description": "Leather jacket",
"brand": "Lee jeans",
"color": "brown",
"product_id": "123456"
},
{
"id": 2,
"description": "Leather jacket",
"brand": "Lee jeans",
"color": "black",
"product_id": "123456"
}
]
You may want to ignore the different colors of an item. To do so, you can set product_id
as a distinctAttribute
.
$ curl \
-X POST 'http://localhost:7700/indexes/jackets/settings' \
--data '{
"distinctAttribute": "product_id"
}
client.index('movies').updateSettings({
distinctAttribute: 'product_id'
})
client.index('movies').update_settings({
'distinctAttribute': 'product_id'
})
$client->index('jackets')->updateDistinctAttribute('product_id');
client.index('jackets').update_distinct_attribute('product_id')
client.Settings("jackets").UpdateDistinctAttribute("movie_id")
let jackets: Index = client.get_index("jackets").await.unwrap();
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 \
-X POST 'http://localhost:7700/indexes/movies/settings' \
--data '{
"searchableAttributes": [
"title",
"description",
"genre"
]
}'
client.index('movies').updateSettings({
searchableAttributes: [
'title',
'description',
'genre'
]
})
client.index('movies').update_settings({
'searchableAttributes': [
'title',
'description',
'genre'
]
})
$client->index('movies')->updateSearchableAttributes([
'title',
'description',
'genre'
]);
index.update_settings({
searchableAttributes: [
'title',
'description',
'genre'
]
})
searchableAttributes := []string{
"title",
"description",
"genre",
}
client.Settings("movies").UpdateSearchableAttributes(searchableAttributes)
let searchable_attributes = &[
"title",
"description",
"genre"
];
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 \
-X POST 'http://localhost:7700/indexes/movies/settings' \
--data '{
"displayedAttributes": [
"title",
"description",
"genre",
"release_date"
]
}'
client.index('movies').updateSettings({
displayedAttributes: [
'title',
'description',
'genre',
'release_date',
]
})
client.index('movies').update_settings({
'displayedAttributes': [
'title',
'description',
'genre',
'release_date'
]
})
$client->index('movies')->updateDisplayedAttributes([
'title',
'description',
'genre',
'release_date'
]);
index.update_settings({
displayedAttributes: [
'title',
'description',
'genre',
'release_date'
]
})
displayedAttributes := []string{
"title",
"description",
"genre",
"release_date",
}
client.Settings("movies").UpdateDisplayedAttributes(displayedAttributes)
let displayed_attributes = &[
"title",
"description",
"genre",
"release_date"
];
let progress: Progress = movies.set_displayed_attributes(displayed_attributes).await.unwrap();