Synonyms
Child route of the settings route.
Synonyms
is an object containing words and their respective synonyms. A synonym in MeiliSearch is considered equal to its associated word in a search query.
Synonyms can also be updated directly through the global settings route along with the other settings.
To learn more about synonyms, 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 synonyms
GET
/indexes/:index_uid/settings/synonyms
Get the list of synonyms of an index.
Path variables
Variable | Description |
---|---|
index_uid | The index UID |
Example
<>
cURL
JS
Python
PHP
Java
Ruby
Go
Rust
Swift
Dart
curl \
-X GET 'http://localhost:7700/indexes/movies/settings/synonyms'
client.index('movies').getSynonyms()
client.index('movies').get_synonyms()
$client->index('movies')->getSynonyms();
client.index("movies").getSynonyms();
client.index('movies').synonyms
client.Index("movies").GetSynonyms()
let synonyms: HashMap<String, Vec<String>> = movies.get_synonyms().await.unwrap();
client.index("movies").getSynonyms { (result: Result<[String: [String]], Swift.Error>) in
switch result {
case .success(let synonyms):
print(update)
case .failure(let error):
print(error)
}
}
await client.index('movies').get_synonyms()
Response: 200 OK
{
"wolverine": [
"xmen",
"logan"
],
"logan": [
"wolverine",
"xmen"
],
"wow": [
"world of warcraft"
]
}
Update synonyms
POST
/indexes/:index_uid/settings/synonyms
Update the list of synonyms of an index. Synonyms are normalized.
Path variables
Variable | Description |
---|---|
index_uid | The index UID |
Body
An object that contains all synonyms and their associated words.
More information about the body.
Example
<>
cURL
JS
Python
PHP
Java
Ruby
Go
Rust
Swift
Dart
curl \
-X POST 'http://localhost:7700/indexes/movies/settings/synonyms' \
-H 'Content-Type: application/json' \
--data-binary '{
"wolverine": ["xmen", "logan"],
"logan": ["wolverine", "xmen"],
"wow": ["world of warcraft"]
}'
client.index('movies').updateSynonyms({
wolverine: ['xmen', 'logan'],
logan: ['wolverine', 'xmen'],
wow: ['world of warcraft']
})
client.index('movies').update_synonyms({
'wolverine': ['xmen', 'logan'],
'logan': ['wolverine', 'xmen'],
'wow': ['world of warcraft']
})
$client->index('movies')->updateSynonyms([
'wolverine' => ['xmen', 'logan'],
'logan' => ['wolverine', 'xmen'],
'wow' => ['world of warcraft']
]);
Settings settings = new Settings();
HashMap<String, String[]> synonyms = new HashMap<String, String[]>();
synonyms.put("wolverine", new String[] {"xmen", "logan"});
synonyms.put("logan", new String[] {"wolverine"});
settings.setSynonyms(synonyms);
client.index("movies").updateSettings(settings);
client.index('movies').update_synonyms({
wolverine: ['xmen', 'logan'],
logan: ['wolverine', 'xmen'],
wow: ['world of warcraft']
})
synonyms := map[string][]string{
"wolverine": []string{"xmen", "logan"},
"logan": []string{"wolverine", "xmen"},
"wow": []string{"world of warcraft"},
}
client.Index("movies").UpdateSynonyms(&synonyms)
let mut synonyms = std::collections::HashMap::new();
synonyms.insert(String::from("wolverine"), vec![String::from("xmen"), String::from("logan")]);
synonyms.insert(String::from("logan"), vec![String::from("xmen"), String::from("wolverine")]);
synonyms.insert(String::from("wow"), vec![String::from("world of warcraft")]);
let progress: Progress = movies.set_synonyms(&synonyms).await.unwrap();
let synonyms: [String: [String]] = [
"wolverine": ["xmen", "logan"],
"logan": ["wolverine", "xmen"],
"wow": ["world of warcraft"]
]
client.index("movies").updateSynonyms(synonyms) { (result: Result<Update, Swift.Error>) in
switch result {
case .success(let update):
print(update)
case .failure(let error):
print(error)
}
}
await client.index('movies').updateSynonyms(
{
'wolverine': ['xmen', 'logan'],
'logan': ['wolverine', 'xmen'],
'wow': ['world of warcraft']
}
);
Response: 202 Accepted
{ "updateId": 1 }
This updateId
allows you to track the current update.
Reset synonyms
DELETE
/indexes/:index_uid/settings/synonyms
Reset the list of synonyms of an index to its default value.
Default value
Empty object : {}
Path variables
Variable | Description |
---|---|
index_uid | The index UID |
Example
<>
cURL
JS
Python
PHP
Java
Ruby
Go
Rust
Swift
Dart
curl \
-X DELETE 'http://localhost:7700/indexes/movies/settings/synonyms'
client.index('movies').resetSynonyms()
client.index('movies').reset_synonyms()
$client->index('movies')->resetSynonyms();
//Not yet implemented
client.index('movies').reset_synonyms
client.Index("movies").ResetSynonyms()
movies.reset_synonyms().await.unwrap();
client.index("movies").resetSynonyms { (result: Result<Update, Swift.Error>) in
switch result {
case .success(let update):
print(update)
case .failure(let error):
print(error)
}
}
await client.index('movies').resetSynonyms();
Response: 202 Accepted
{ "updateId": 1 }
This updateId
allows you to track the current update.