Required ACL: editSettings
You need to provide a unique objectID
for the synonym you want to add or replace:
objectID
isn’t a reference to an Algolia record: it’s a unique identifier of a synonym object.
If a synonym with the provided objectID
exists, the synonym is replaced,
otherwise a new synonym is added.
For more information, see Synonyms .
To add multiple synonyms in a single API request,
use the saveSynonyms
method.
Examples
Add or update a regular synonym, where all the words are equivalent
C#
Go
Java
JavaScript
Kotlin
PHP
Python
Ruby
Scala
Swift
var synonym = new Synonym
{
ObjectID = "synonymID" ,
Type = "synonym" ,
Synonyms = new List < string > { "car" , "vehicle" , "auto" }
};
index . SaveSynonym ( synonym , forwardToReplicas : true );
// Asynchronous
await index . SaveSynonymAsync ( synonym , forwardToReplicas : true );
Add or update a one way synonym
C#
Go
Java
JavaScript
Kotlin
PHP
Python
Ruby
Scala
Swift
var synonym = new Synonym
{
ObjectID = "synonymID" ,
Type = "oneWaySynonym" ,
Input = "car" ,
Synonyms = new List < string > { "vehicle" , "auto" }
};
index . SaveSynonym ( synonym , forwardToReplicas : true );
// Asynchronous
await index . SaveSynonymAsync ( synonym , forwardToReplicas : true );
Add or update an alternative correction 1 synonym
C#
Go
Java
JavaScript
Kotlin
PHP
Python
Ruby
Scala
Swift
var synonym = new Synonym
{
ObjectID = "synonymID" ,
Type = "altCorrection1" ,
Input = "car" ,
Synonyms = new List < string > { "vehicle" , "auto" }
};
index . SaveSynonym ( synonym , forwardToReplicas : true );
// Asynchronous
await index . SaveSynonymAsync ( synonym , forwardToReplicas : true );
Add or update an alternative correction 2 synonym
C#
Go
Java
JavaScript
Kotlin
PHP
Python
Ruby
Scala
Swift
var synonym = new Synonym
{
ObjectID = "synonymID" ,
Type = "altCorrection2" ,
Input = "car" ,
Synonyms = new List < string > { "vehicle" , "auto" }
};
index . SaveSynonym ( synonym , forwardToReplicas : true );
// Asynchronous
await index . SaveSynonymAsync ( synonym , forwardToReplicas : true );
Add or update a placeholder synonym
To create placeholders, enclose the desired terms in angle brackets in the records.
Consider this record:
{
"address" : "589 Howard <Street>"
}
<Street>
refers to the placeholder as defined
below when the synonym is created:
C#
Go
Java
JavaScript
Kotlin
PHP
Python
Ruby
Scala
Swift
var synonym = new Synonym
{
ObjectID = "synonymID" ,
Type = "placeholder" ,
Placeholder = "<Street>" ,
Synonyms = new List < string > { "street" , "st" }
};
index . SaveSynonym ( synonym , forwardToReplicas : true );
// Asynchronous
await index . SaveSynonymAsync ( synonym , forwardToReplicas : true );
Parameters
A synonym object. The synonym type can be one of the following values:
altCorrection1
altCorrection2
oneWaySynonym
placeholder
synonym
List of corrections.
Required for synonym types altCorrection1
or altCorrection2
.
A word or expression, used as the basis for synonyms.
Required for synonym type oneWaySynonym
.
Must contain the same value as the objectId
above.
Only required in some programming languages.
A single word, used as the basis for replacements.
Required for synonym type placeholder
.
List of replacements for the placeholder.
Required for synonym type placeholder
.
List of synonyms (up to 20 for type synonym
and 100 for type oneWaySynonym
).
Required for synonym types synonym
or oneWaySynonym
.
A single word, used as the basis for corrections.
Required for synonym types altCorrection1
or altCorrection2
.
By default, this method applies only to the specified index.
By making this true, the method will also send the synonym to all replicas.
Thus, if you want to forward your synonyms to replicas you will need to specify that.
Response
objectID of the inserted object.
The task ID used with the waitTask
method.
Date at which the indexing job has been created.
Response as JSON
This section shows the JSON response returned by the API.
Each API client wraps this response in language-specific objects, so the structure may vary.
To view the response, use the getLogs
method.
Don’t rely on the order of properties—JSON objects don’t preserve key order.
{
"updatedAt" : "2013-01-18T15:33:13.556Z" ,
"taskID" : 678 ,
"id" : "6891"
}