client.execute { save synonym Synonym( "synonymID", Seq("car", "vehicle", "auto") ) inIndex "index_name" and forwardToReplicas}
let synonym: Synonym = .multiWay(objectID: "synonymID", synonyms: ["car", "vehicle", "auto"])index.saveSynonym(synonym, forwardToReplicas: true) { result in if case .success(let response) = result { print("Response: \(response)") }}
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);// Asynchronousawait index.SaveSynonymAsync(synonym, forwardToReplicas: true);
client.execute { save synonym OneWaySynonym( "synonymID", "car", Seq("vehicle", "auto") ) inIndex "index_name" and forwardToReplicas}
let synonym: Synonym = .oneWay(objectID: "synonymID", input: "car", synonyms: ["vehicle", "auto"])index.saveSynonym(synonym, forwardToReplicas: true) { result in if case .success(let response) = result { print("Response: \(response)") }}
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);// Asynchronousawait index.SaveSynonymAsync(synonym, forwardToReplicas: true);
client.execute { save synonym AltCorrection1( "synonymID", "car", Seq("vehicle", "auto") ) inIndex "index_name" and forwardToReplicas}
let synonym: Synonym = .alternativeCorrection(objectID: "synonymID", word: "car", corrections: ["vehicle", "auto"], typo: .one)index.saveSynonym(synonym, forwardToReplicas: true) { result in if case .success(let response) = result { print("Response: \(response)") }}
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);// Asynchronousawait index.SaveSynonymAsync(synonym, forwardToReplicas: true);
client.execute { save synonym AltCorrection2( "synonymID", "car", Seq("vehicle", "auto") ) inIndex "index_name" and forwardToReplicas}
let synonym: Synonym = .alternativeCorrection(objectID: "synonymID", word: "car", corrections: ["vehicle", "auto"], typo: .two)index.saveSynonym(synonym, forwardToReplicas: true) { result in if case .success(let response) = result { print("Response: \(response)") }}
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);// Asynchronousawait index.SaveSynonymAsync(synonym, forwardToReplicas: true);
client.execute { save synonym Placeholder( "synonymID", "<Street>", Seq("street", "st") ) inIndex "index_name" and forwardToReplicas}
let synonym: Synonym = .placeholder(objectID: "synonymID", placeholder: "street", replacements: ["street", "st"])index.saveSynonym(synonym, forwardToReplicas: true) { result in if case .success(let response) = result { print("Response: \(response)") }}
Parameters
object
required
A synonym object.
Show child attributes
string
required
The synonym type can be one of the following values:
altCorrection1
altCorrection2
oneWaySynonym
placeholder
synonym
string[]
List of corrections.
Required for synonym types altCorrection1 or altCorrection2.
string
A word or expression, used as the basis for synonyms.
Required for synonym type oneWaySynonym.
string
Must contain the same value as the objectId above.
Only required in some programming languages.
string
A single word, used as the basis for replacements.
Required for synonym type placeholder.
string[]
List of replacements for the placeholder.
Required for synonym type placeholder.
string[]
List of synonyms (up to 20 for type synonym and 100 for type oneWaySynonym).
Required for synonym types synonym or oneWaySynonym.
string
A single word, used as the basis for corrections.
Required for synonym types altCorrection1 or altCorrection2.
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.
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.