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

  1. /indexes/:index_uid/settings/synonyms

Get the list of synonyms of an index.

Path variables

VariableDescription
index_uidThe index UID

Example

<>

cURL

JS

Python

PHP

Java

Ruby

Go

Rust

Swift

Dart

  1. curl \
  2. -X GET 'http://localhost:7700/indexes/movies/settings/synonyms'
  1. client.index('movies').getSynonyms()
  1. client.index('movies').get_synonyms()
  1. $client->index('movies')->getSynonyms();
  1. client.index("movies").getSynonyms();
  1. client.index('movies').synonyms
  1. client.Index("movies").GetSynonyms()
  1. let synonyms: HashMap<String, Vec<String>> = movies.get_synonyms().await.unwrap();
  1. client.index("movies").getSynonyms { (result: Result<[String: [String]], Swift.Error>) in
  2. switch result {
  3. case .success(let synonyms):
  4. print(update)
  5. case .failure(let error):
  6. print(error)
  7. }
  8. }
  1. await client.index('movies').get_synonyms()

Response: 200 OK

  1. {
  2. "wolverine": [
  3. "xmen",
  4. "logan"
  5. ],
  6. "logan": [
  7. "wolverine",
  8. "xmen"
  9. ],
  10. "wow": [
  11. "world of warcraft"
  12. ]
  13. }

Update synonyms

POST

  1. /indexes/:index_uid/settings/synonyms

Update the list of synonyms of an index. Synonyms are normalized.

Path variables

VariableDescription
index_uidThe 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

  1. curl \
  2. -X POST 'http://localhost:7700/indexes/movies/settings/synonyms' \
  3. -H 'Content-Type: application/json' \
  4. --data-binary '{
  5. "wolverine": ["xmen", "logan"],
  6. "logan": ["wolverine", "xmen"],
  7. "wow": ["world of warcraft"]
  8. }'
  1. client.index('movies').updateSynonyms({
  2. wolverine: ['xmen', 'logan'],
  3. logan: ['wolverine', 'xmen'],
  4. wow: ['world of warcraft']
  5. })
  1. client.index('movies').update_synonyms({
  2. 'wolverine': ['xmen', 'logan'],
  3. 'logan': ['wolverine', 'xmen'],
  4. 'wow': ['world of warcraft']
  5. })
  1. $client->index('movies')->updateSynonyms([
  2. 'wolverine' => ['xmen', 'logan'],
  3. 'logan' => ['wolverine', 'xmen'],
  4. 'wow' => ['world of warcraft']
  5. ]);
  1. Settings settings = new Settings();
  2. HashMap<String, String[]> synonyms = new HashMap<String, String[]>();
  3. synonyms.put("wolverine", new String[] {"xmen", "logan"});
  4. synonyms.put("logan", new String[] {"wolverine"});
  5. settings.setSynonyms(synonyms);
  6. client.index("movies").updateSettings(settings);
  1. client.index('movies').update_synonyms({
  2. wolverine: ['xmen', 'logan'],
  3. logan: ['wolverine', 'xmen'],
  4. wow: ['world of warcraft']
  5. })
  1. synonyms := map[string][]string{
  2. "wolverine": []string{"xmen", "logan"},
  3. "logan": []string{"wolverine", "xmen"},
  4. "wow": []string{"world of warcraft"},
  5. }
  6. client.Index("movies").UpdateSynonyms(&synonyms)
  1. let mut synonyms = std::collections::HashMap::new();
  2. synonyms.insert(String::from("wolverine"), vec![String::from("xmen"), String::from("logan")]);
  3. synonyms.insert(String::from("logan"), vec![String::from("xmen"), String::from("wolverine")]);
  4. synonyms.insert(String::from("wow"), vec![String::from("world of warcraft")]);
  5. let progress: Progress = movies.set_synonyms(&synonyms).await.unwrap();
  1. let synonyms: [String: [String]] = [
  2. "wolverine": ["xmen", "logan"],
  3. "logan": ["wolverine", "xmen"],
  4. "wow": ["world of warcraft"]
  5. ]
  6. client.index("movies").updateSynonyms(synonyms) { (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.index('movies').updateSynonyms(
  2. {
  3. 'wolverine': ['xmen', 'logan'],
  4. 'logan': ['wolverine', 'xmen'],
  5. 'wow': ['world of warcraft']
  6. }
  7. );

Response: 202 Accepted

  1. { "updateId": 1 }

This updateId allows you to track the current update.

Reset synonyms

DELETE

  1. /indexes/:index_uid/settings/synonyms

Reset the list of synonyms of an index to its default value.

Default value

Empty object : {}

Path variables

VariableDescription
index_uidThe index UID

Example

<>

cURL

JS

Python

PHP

Java

Ruby

Go

Rust

Swift

Dart

  1. curl \
  2. -X DELETE 'http://localhost:7700/indexes/movies/settings/synonyms'
  1. client.index('movies').resetSynonyms()
  1. client.index('movies').reset_synonyms()
  1. $client->index('movies')->resetSynonyms();
  1. //Not yet implemented
  1. client.index('movies').reset_synonyms
  1. client.Index("movies").ResetSynonyms()
  1. movies.reset_synonyms().await.unwrap();
  1. client.index("movies").resetSynonyms { (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').resetSynonyms();

Response: 202 Accepted

  1. { "updateId": 1 }

This updateId allows you to track the current update.