Skip to main content
This page documents an earlier version of the API client. For the latest version, see Create or replace a synonym.
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

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

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

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

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:
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

synonym
object
required
A synonym object.
forwardToReplicas
boolean
default:false
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

id
string
objectID of the inserted object.
taskID
integer
The task ID used with the waitTask method.
updatedAt
string
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.
JSON
{
  "updatedAt":"2013-01-18T15:33:13.556Z",
  "taskID": 678,
  "id": "6891"
}
I