editSettings
You need to provide a unique objectID for the synonym you want to add or replace:
objectIDisn’t a reference to an Algolia record: it’s a unique identifier of a synonym object.- If a synonym with the provided
objectIDexists, the synonym is replaced, otherwise a new synonym is added.
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);
forwardToReplicas := opt.ForwardToReplicas(true)
synonym := search.NewRegularSynonym(
"synonymID",
"car",
"vehicle",
"auto",
)
res, err := index.SaveSynonym(synonym, forwardToReplicas)
bool forwardToReplicas = true;
Synonym synonym = Synonym.createSynonym(
"synonymID",
Arrays.asList("car", "vehicle", "auto"));
// or
Synonym synonym = new Synonym()
.setObjectID("synonymID")
.setType(SynonymType.SYNONYM)
.setSynonyms(Arrays.asList("car", "vehicle", "auto"));
// Sync version
index.saveSynonym(synonym, forwardToReplicas);
// Async version
index.saveSynonymAsync(synonym, forwardToReplicas);
index.saveSynonym({
objectID: 'synonymID',
type: 'synonym',
synonyms: ['car', 'vehicle', 'auto']
}, { forwardToReplicas: true }).then(() => {
// done
});
val synonym = Synonym.MultiWay(
objectID = ObjectID("synonymID"),
synonyms = listOf("car", "vehicle", "auto")
)
index.saveSynonym(synonym, forwardToReplicas = true)
$index->saveSynonym([
'objectID' => 'synonymID',
'type' => 'synonym',
'synonyms' => [
'car',
'vehicle',
'auto'
]
], [
'forwardToReplicas' => true
]);
index.save_synonym({
'objectID': 'synonymID',
'type': 'synonym',
'synonyms': ['car', 'vehicle', 'auto']
}, {
'forwardToReplicas': True
})
index.save_synonym({
objectID: 'synonymID',
type: 'synonym',
synonyms: ['car', 'vehicle', 'auto']
}, { forwardToReplicas: true })
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);
// Asynchronous
await index.SaveSynonymAsync(synonym, forwardToReplicas: true);
forwardToReplicas := opt.ForwardToReplicas(true)
synonym := search.NewOneWaySynonym(
"synonymID",
"car",
"vehicle",
"auto",
)
res, err := index.SaveSynonym(synonym, forwardToReplicas)
bool forwardToReplicas = true;
Synonym synonym = Synonym.createOneWaySynonym(
"synonymID", "car",
Arrays.asList("vehicle", "auto"));
// or
Synonym synonym = new Synonym()
.setObjectID("synonymID")
.setType(SynonymType.ONE_WAY_SYNONYM)
.setInput("car")
.setSynonyms(Arrays.asList("vehicle", "auto"));
// Sync version
index.saveSynonym(synonym, forwardToReplicas);
// Async version
index.saveSynonymAsync(synonym, forwardToReplicas);
index.saveSynonym({
objectID: 'synonymID',
type: 'oneWaySynonym',
input: 'car',
synonyms: ['vehicle', 'auto']
}, { forwardToReplicas: true }).then(() => {
// done
});
val synonym = Synonym.OneWay(
objectID = ObjectID("synonymID"),
input = "car",
synonyms = listOf("vehicle", "auto")
)
index.saveSynonym(synonym, forwardToReplicas = true)
$index->saveSynonym([
'objectID' => 'synonymID',
'type' => 'oneWaySynonym',
'input' => 'car',
'synonyms' => [
'vehicle',
'auto'
], [
'forwardToReplicas' => true
]);
index.save_synonym({
'objectID': 'synonymID',
'type': 'oneWaySynonym',
'input': 'car',
'synonyms': [
'vehicle',
'auto'
]
}, {
'forwardToReplicas': True
})
index.save_synonym({
objectID: 'synonymID',
type: 'oneWaySynonym',
input: 'car',
synonyms: ['vehicle', 'auto']
}, { 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);
// Asynchronous
await index.SaveSynonymAsync(synonym, forwardToReplicas: true);
forwardToReplicas := opt.ForwardToReplicas(true)
synonym := search.NewAltCorrection1(
"synonymID",
"car",
"vehicle",
"auto",
)
res, err := index.SaveSynonym(synonym, forwardToReplicas)
bool forwardToReplicas = true;
Synonym synonym = Synonym.createAltCorrection1(
"synonymID", "car",
Arrays.asList("vehicle", "auto"));
// or
Synonym synonym = new Synonym()
.setObjectID("synonymID")
.setType(SynonymType.ALT_CORRECTION_1)
.setWord("car")
.setCorrections(Arrays.asList("vehicle", "auto"));
// Sync version
index.saveSynonym(synonym, forwardToReplicas);
// Async version
index.saveSynonymAsync(synonym, forwardToReplicas);
index.saveSynonym({
objectID: 'synonymID',
type: 'altCorrection1',
word: 'car',
corrections: ['vehicle', 'auto']
}, { forwardToReplicas: true }).then(() => {
// done
});
val synonym = Synonym.AlternativeCorrections(
objectID = ObjectID("synonymID"),
corrections = listOf("vehicle", "auto"),
typo = SynonymType.Typo.One,
word = "car"
)
index.saveSynonym(synonym, forwardToReplicas = true)
$index->saveSynonym([
'objectID' => 'synonymID',
'type' => 'altCorrection1',
'word' => 'car',
'corrections' => [
'vehicle',
'auto'
]
], [
'forwardToReplicas' => true
]);
index.save_synonym({
'objectID': 'synonymID',
'type': 'altCorrection1',
'word': 'car',
'corrections': [
'vehicle',
'auto'
]
}, {
'forwardToReplicas': True
})
index.save_synonym({
objectID: 'synonymID',
type: 'altCorrection1',
word: 'car',
corrections: ['vehicle', 'auto']
}, { 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);
// Asynchronous
await index.SaveSynonymAsync(synonym, forwardToReplicas: true);
forwardToReplicas := opt.ForwardToReplicas(true)
synonym := search.NewAltCorrection2(
"synonymID",
"car",
"vehicle",
"auto",
)
res, err := index.SaveSynonym(synonym, forwardToReplicas)
bool forwardToReplicas = true;
Synonym synonym = Synonym.createAltCorrection2(
"synonymID", "car",
Arrays.asList("vehicle", "auto"));
// or
Synonym synonym = new Synonym()
.setObjectID("synonymID")
.setType(SynonymType.ALT_CORRECTION_2)
.setWord("car")
.setCorrections(Arrays.asList("vehicle", "auto"));
// Sync version
index.saveSynonym(synonym, forwardToReplicas);
// Async version
index.saveSynonymAsync(synonym, forwardToReplicas);
index.saveSynonym({
objectID: 'synonymID',
type: 'altCorrection2',
word: 'car',
corrections: ['vehicle', 'auto']
}, { forwardToReplicas: true }).then(() => {
// done
});
val synonym = Synonym.AlternativeCorrections(
objectID = ObjectID("synonymID"),
corrections = listOf("vehicle", "auto"),
typo = SynonymType.Typo.One,
word = "car"
)
index.saveSynonym(synonym, forwardToReplicas = true)
$index->saveSynonym([
'objectID' => 'synonymID',
'type' => 'altCorrection2',
'word' => 'car',
'corrections' => [
'vehicle',
'auto'
]
], [
'forwardToReplicas' => true
]);
index.save_synonym({
'objectID': 'synonymID',
'type': 'altCorrection2',
'word': 'car',
'corrections': [
'vehicle',
'auto'
]
}, {
'forwardToReplicas': True
})
index.save_synonym({
objectID: 'synonymID',
type: 'altCorrection2',
word: 'car',
corrections: ['vehicle', 'auto']
}, { 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);
// Asynchronous
await index.SaveSynonymAsync(synonym, forwardToReplicas: true);
forwardToReplicas := opt.ForwardToReplicas(true)
synonym := search.NewPlaceholder(
"synonymID",
"<Street>",
"street",
"st",
)
res, err := index.SaveSynonym(synonym, forwardToReplicas)
bool forwardToReplicas = true;
Synonym synonym = Synonym.createPlaceHolder(
"synonymID", "<Street>",
Arrays.asList("street", "st"));
// or
Synonym synonym = new Synonym()
.setObjectID("synonymID")
.setType(SynonymType.PLACEHOLDER)
.setPlaceholder("<Street>")
.setCorrections(Arrays.asList("street", "st")),
// Sync version
index.saveSynonym(synonym, forwardToReplicas);
// Async version
index.saveSynonymAsync(synonym, forwardToReplicas);
index.saveSynonym({
objectID: 'synonymID',
type: 'placeholder',
placeholder: '<Street>',
replacements: ['street', 'st']
}, { forwardToReplicas: true }).then(() => {
// done
});
val synonym = Synonym.Placeholder(
objectID = ObjectID("synonymID"),
placeholder = Synonym.Placeholder.Token("street"),
replacements = listOf("street", "st")
)
index.saveSynonym(synonym, forwardToReplicas = true)
$index->saveSynonym([
'objectID' => 'synonymID',
'type' => 'placeholder',
'placeholder' => '<Street>',
'replacements' => [
'street',
'st'
]
], [
'forwardToReplicas' => true
]);
index.save_synonym({
'objectID': 'synonymID',
'type': 'placeholder',
'placeholder': '<Street>',
'replacements': [
'street',
'auto'
]
}, {
'forwardToReplicas': True
})
index.save_synonym({
objectID: 'synonymID',
type: 'placeholder',
placeholder: '<Street>',
replacements: [
'street',
'st'
]
}, { 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
Show child attributes
string
required
The synonym type can be one of the following values:
altCorrection1altCorrection2oneWaySynonymplaceholdersynonym
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.
Response
string
objectID of the inserted object.
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 thegetLogs 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"
}