curl --request POST \
--url 'https://algolia_application_id.algolia.net/1/indexes/ALGOLIA_INDEX_NAME/synonyms/batch?forwardToReplicas=true&replaceExistingSynonyms=true' \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--header 'x-algolia-api-key: ALGOLIA_API_KEY' \
--header 'x-algolia-application-id: ALGOLIA_APPLICATION_ID' \
--data '
[
{
"objectID": "synonymID",
"type": "onewaysynonym",
"synonyms": [
"vehicle",
"auto"
],
"input": "car",
"word": "car",
"corrections": [
"vehicle",
"auto"
],
"placeholder": "<Street>",
"replacements": [
"street",
"st"
]
}
]
'// Initialize the client
var client = new SearchClient(new SearchConfig("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY"));
// Call the API
var response = await client.SaveSynonymsAsync(
"<YOUR_INDEX_NAME>",
new List<SynonymHit>
{
new SynonymHit
{
ObjectID = "id1",
Type = Enum.Parse<SynonymType>("Synonym"),
Synonyms = new List<string> { "car", "vehicule", "auto" },
},
new SynonymHit
{
ObjectID = "id2",
Type = Enum.Parse<SynonymType>("Onewaysynonym"),
Input = "iphone",
Synonyms = new List<string> { "ephone", "aphone", "yphone" },
},
},
true,
true
);
// print the response
Console.WriteLine(response);// Initialize the client
final client =
SearchClient(appId: 'ALGOLIA_APPLICATION_ID', apiKey: 'ALGOLIA_API_KEY');
// Call the API
final response = await client.saveSynonyms(
indexName: "<YOUR_INDEX_NAME>",
synonymHit: [
SynonymHit(
objectID: "id1",
type: SynonymType.fromJson("synonym"),
synonyms: [
"car",
"vehicule",
"auto",
],
),
SynonymHit(
objectID: "id2",
type: SynonymType.fromJson("onewaysynonym"),
input: "iphone",
synonyms: [
"ephone",
"aphone",
"yphone",
],
),
],
forwardToReplicas: true,
replaceExistingSynonyms: true,
);
// print the response
print(response);// Initialize the client
client, err := search.NewClient("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY")
if err != nil {
// The client can fail to initialize if you pass an invalid parameter.
panic(err)
}
// Call the API
response, err := client.SaveSynonyms(client.NewApiSaveSynonymsRequest(
"<YOUR_INDEX_NAME>",
[]search.SynonymHit{*search.NewEmptySynonymHit().SetObjectID("id1").SetType(search.SynonymType("synonym")).SetSynonyms(
[]string{"car", "vehicle", "auto"}), *search.NewEmptySynonymHit().SetObjectID("id2").SetType(search.SynonymType("onewaysynonym")).SetInput("iphone").SetSynonyms(
[]string{"ephone", "aphone", "yphone"})}).WithForwardToReplicas(true).WithReplaceExistingSynonyms(true))
if err != nil {
// handle the eventual error
panic(err)
}
// print the response
print(response)// Initialize the client
SearchClient client = new SearchClient("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY");
// Call the API
UpdatedAtResponse response = client.saveSynonyms(
"<YOUR_INDEX_NAME>",
Arrays.asList(
new SynonymHit()
.setObjectID("id1")
.setType(SynonymType.SYNONYM)
.setSynonyms(Arrays.asList("car", "vehicule", "auto")),
new SynonymHit()
.setObjectID("id2")
.setType(SynonymType.ONEWAYSYNONYM)
.setInput("iphone")
.setSynonyms(Arrays.asList("ephone", "aphone", "yphone"))
),
true,
true
);
// print the response
System.out.println(response);// Initialize the client
const client = algoliasearch('ALGOLIA_APPLICATION_ID', 'ALGOLIA_API_KEY');
// Call the API
const response = await client.saveSynonyms({
indexName: '<YOUR_INDEX_NAME>',
synonymHit: [
{ objectID: 'id1', type: 'synonym', synonyms: ['car', 'vehicule', 'auto'] },
{ objectID: 'id2', type: 'onewaysynonym', input: 'iphone', synonyms: ['ephone', 'aphone', 'yphone'] },
],
forwardToReplicas: true,
replaceExistingSynonyms: true,
});
// print the response
console.log(response);// Initialize the client
val client = SearchClient(appId = "ALGOLIA_APPLICATION_ID", apiKey = "ALGOLIA_API_KEY")
// Call the API
var response =
client.saveSynonyms(
indexName = "<YOUR_INDEX_NAME>",
synonymHit =
listOf(
SynonymHit(
objectID = "id1",
type = SynonymType.entries.first { it.value == "synonym" },
synonyms = listOf("car", "vehicule", "auto"),
),
SynonymHit(
objectID = "id2",
type = SynonymType.entries.first { it.value == "onewaysynonym" },
input = "iphone",
synonyms = listOf("ephone", "aphone", "yphone"),
),
),
forwardToReplicas = true,
replaceExistingSynonyms = true,
)
// print the response
println(response)// Initialize the client
$client = SearchClient::create('ALGOLIA_APPLICATION_ID', 'ALGOLIA_API_KEY');
// Call the API
$response = $client->saveSynonyms(
'<YOUR_INDEX_NAME>',
[
['objectID' => 'id1',
'type' => 'synonym',
'synonyms' => [
'car',
'vehicule',
'auto',
],
],
['objectID' => 'id2',
'type' => 'onewaysynonym',
'input' => 'iphone',
'synonyms' => [
'ephone',
'aphone',
'yphone',
],
],
],
true,
true,
);
// print the response
var_dump($response);# Initialize the client
# In an asynchronous context, you can use SearchClient instead, which exposes the exact same methods.
client = SearchClientSync("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY")
# Call the API
response = client.save_synonyms(
index_name="<YOUR_INDEX_NAME>",
synonym_hit=[
{
"objectID": "id1",
"type": "synonym",
"synonyms": [
"car",
"vehicule",
"auto",
],
},
{
"objectID": "id2",
"type": "onewaysynonym",
"input": "iphone",
"synonyms": [
"ephone",
"aphone",
"yphone",
],
},
],
forward_to_replicas=True,
replace_existing_synonyms=True,
)
# print the response
print(response)# Initialize the client
client = Algolia::SearchClient.create("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY")
# Call the API
response = client.save_synonyms(
"<YOUR_INDEX_NAME>",
[
Algolia::Search::SynonymHit.new(algolia_object_id: "id1", type: "synonym", synonyms: ["car", "vehicule", "auto"]),
Algolia::Search::SynonymHit.new(
algolia_object_id: "id2",
type: "onewaysynonym",
input: "iphone",
synonyms: ["ephone", "aphone", "yphone"]
)
],
true,
true
)
# print the response
puts(response)// Initialize the client
val client = SearchClient(appId = "ALGOLIA_APPLICATION_ID", apiKey = "ALGOLIA_API_KEY")
// Call the API
val response = Await.result(
client.saveSynonyms(
indexName = "<YOUR_INDEX_NAME>",
synonymHit = Seq(
SynonymHit(
objectID = "id1",
`type` = SynonymType.withName("synonym"),
synonyms = Some(Seq("car", "vehicule", "auto"))
),
SynonymHit(
objectID = "id2",
`type` = SynonymType.withName("onewaysynonym"),
input = Some("iphone"),
synonyms = Some(Seq("ephone", "aphone", "yphone"))
)
),
forwardToReplicas = Some(true),
replaceExistingSynonyms = Some(true)
),
Duration(100, "sec")
)
// print the response
println(response)// Initialize the client
let client = try SearchClient(appID: "ALGOLIA_APPLICATION_ID", apiKey: "ALGOLIA_API_KEY")
// Call the API
let response = try await client.saveSynonyms(
indexName: "<YOUR_INDEX_NAME>",
synonymHit: [
SynonymHit(objectID: "id1", type: SynonymType.synonym, synonyms: ["car", "vehicule", "auto"]),
SynonymHit(
objectID: "id2",
type: SynonymType.onewaysynonym,
synonyms: ["ephone", "aphone", "yphone"],
input: "iphone"
),
],
forwardToReplicas: true,
replaceExistingSynonyms: true
)
// print the response
print(response){
"taskID": 1514562690001,
"updatedAt": "2023-07-04T12:49:15Z"
}{
"message": "Invalid Application-Id or API-Key"
}{
"message": "Invalid Application-Id or API-Key"
}{
"message": "Invalid Application-Id or API-Key"
}{
"message": "Invalid Application-Id or API-Key"
}Create or replace synonyms
If a synonym with the objectID doesnāt exist, Algolia adds a new one. Otherwise, existing synonyms are replaced.
curl --request POST \
--url 'https://algolia_application_id.algolia.net/1/indexes/ALGOLIA_INDEX_NAME/synonyms/batch?forwardToReplicas=true&replaceExistingSynonyms=true' \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--header 'x-algolia-api-key: ALGOLIA_API_KEY' \
--header 'x-algolia-application-id: ALGOLIA_APPLICATION_ID' \
--data '
[
{
"objectID": "synonymID",
"type": "onewaysynonym",
"synonyms": [
"vehicle",
"auto"
],
"input": "car",
"word": "car",
"corrections": [
"vehicle",
"auto"
],
"placeholder": "<Street>",
"replacements": [
"street",
"st"
]
}
]
'// Initialize the client
var client = new SearchClient(new SearchConfig("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY"));
// Call the API
var response = await client.SaveSynonymsAsync(
"<YOUR_INDEX_NAME>",
new List<SynonymHit>
{
new SynonymHit
{
ObjectID = "id1",
Type = Enum.Parse<SynonymType>("Synonym"),
Synonyms = new List<string> { "car", "vehicule", "auto" },
},
new SynonymHit
{
ObjectID = "id2",
Type = Enum.Parse<SynonymType>("Onewaysynonym"),
Input = "iphone",
Synonyms = new List<string> { "ephone", "aphone", "yphone" },
},
},
true,
true
);
// print the response
Console.WriteLine(response);// Initialize the client
final client =
SearchClient(appId: 'ALGOLIA_APPLICATION_ID', apiKey: 'ALGOLIA_API_KEY');
// Call the API
final response = await client.saveSynonyms(
indexName: "<YOUR_INDEX_NAME>",
synonymHit: [
SynonymHit(
objectID: "id1",
type: SynonymType.fromJson("synonym"),
synonyms: [
"car",
"vehicule",
"auto",
],
),
SynonymHit(
objectID: "id2",
type: SynonymType.fromJson("onewaysynonym"),
input: "iphone",
synonyms: [
"ephone",
"aphone",
"yphone",
],
),
],
forwardToReplicas: true,
replaceExistingSynonyms: true,
);
// print the response
print(response);// Initialize the client
client, err := search.NewClient("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY")
if err != nil {
// The client can fail to initialize if you pass an invalid parameter.
panic(err)
}
// Call the API
response, err := client.SaveSynonyms(client.NewApiSaveSynonymsRequest(
"<YOUR_INDEX_NAME>",
[]search.SynonymHit{*search.NewEmptySynonymHit().SetObjectID("id1").SetType(search.SynonymType("synonym")).SetSynonyms(
[]string{"car", "vehicle", "auto"}), *search.NewEmptySynonymHit().SetObjectID("id2").SetType(search.SynonymType("onewaysynonym")).SetInput("iphone").SetSynonyms(
[]string{"ephone", "aphone", "yphone"})}).WithForwardToReplicas(true).WithReplaceExistingSynonyms(true))
if err != nil {
// handle the eventual error
panic(err)
}
// print the response
print(response)// Initialize the client
SearchClient client = new SearchClient("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY");
// Call the API
UpdatedAtResponse response = client.saveSynonyms(
"<YOUR_INDEX_NAME>",
Arrays.asList(
new SynonymHit()
.setObjectID("id1")
.setType(SynonymType.SYNONYM)
.setSynonyms(Arrays.asList("car", "vehicule", "auto")),
new SynonymHit()
.setObjectID("id2")
.setType(SynonymType.ONEWAYSYNONYM)
.setInput("iphone")
.setSynonyms(Arrays.asList("ephone", "aphone", "yphone"))
),
true,
true
);
// print the response
System.out.println(response);// Initialize the client
const client = algoliasearch('ALGOLIA_APPLICATION_ID', 'ALGOLIA_API_KEY');
// Call the API
const response = await client.saveSynonyms({
indexName: '<YOUR_INDEX_NAME>',
synonymHit: [
{ objectID: 'id1', type: 'synonym', synonyms: ['car', 'vehicule', 'auto'] },
{ objectID: 'id2', type: 'onewaysynonym', input: 'iphone', synonyms: ['ephone', 'aphone', 'yphone'] },
],
forwardToReplicas: true,
replaceExistingSynonyms: true,
});
// print the response
console.log(response);// Initialize the client
val client = SearchClient(appId = "ALGOLIA_APPLICATION_ID", apiKey = "ALGOLIA_API_KEY")
// Call the API
var response =
client.saveSynonyms(
indexName = "<YOUR_INDEX_NAME>",
synonymHit =
listOf(
SynonymHit(
objectID = "id1",
type = SynonymType.entries.first { it.value == "synonym" },
synonyms = listOf("car", "vehicule", "auto"),
),
SynonymHit(
objectID = "id2",
type = SynonymType.entries.first { it.value == "onewaysynonym" },
input = "iphone",
synonyms = listOf("ephone", "aphone", "yphone"),
),
),
forwardToReplicas = true,
replaceExistingSynonyms = true,
)
// print the response
println(response)// Initialize the client
$client = SearchClient::create('ALGOLIA_APPLICATION_ID', 'ALGOLIA_API_KEY');
// Call the API
$response = $client->saveSynonyms(
'<YOUR_INDEX_NAME>',
[
['objectID' => 'id1',
'type' => 'synonym',
'synonyms' => [
'car',
'vehicule',
'auto',
],
],
['objectID' => 'id2',
'type' => 'onewaysynonym',
'input' => 'iphone',
'synonyms' => [
'ephone',
'aphone',
'yphone',
],
],
],
true,
true,
);
// print the response
var_dump($response);# Initialize the client
# In an asynchronous context, you can use SearchClient instead, which exposes the exact same methods.
client = SearchClientSync("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY")
# Call the API
response = client.save_synonyms(
index_name="<YOUR_INDEX_NAME>",
synonym_hit=[
{
"objectID": "id1",
"type": "synonym",
"synonyms": [
"car",
"vehicule",
"auto",
],
},
{
"objectID": "id2",
"type": "onewaysynonym",
"input": "iphone",
"synonyms": [
"ephone",
"aphone",
"yphone",
],
},
],
forward_to_replicas=True,
replace_existing_synonyms=True,
)
# print the response
print(response)# Initialize the client
client = Algolia::SearchClient.create("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY")
# Call the API
response = client.save_synonyms(
"<YOUR_INDEX_NAME>",
[
Algolia::Search::SynonymHit.new(algolia_object_id: "id1", type: "synonym", synonyms: ["car", "vehicule", "auto"]),
Algolia::Search::SynonymHit.new(
algolia_object_id: "id2",
type: "onewaysynonym",
input: "iphone",
synonyms: ["ephone", "aphone", "yphone"]
)
],
true,
true
)
# print the response
puts(response)// Initialize the client
val client = SearchClient(appId = "ALGOLIA_APPLICATION_ID", apiKey = "ALGOLIA_API_KEY")
// Call the API
val response = Await.result(
client.saveSynonyms(
indexName = "<YOUR_INDEX_NAME>",
synonymHit = Seq(
SynonymHit(
objectID = "id1",
`type` = SynonymType.withName("synonym"),
synonyms = Some(Seq("car", "vehicule", "auto"))
),
SynonymHit(
objectID = "id2",
`type` = SynonymType.withName("onewaysynonym"),
input = Some("iphone"),
synonyms = Some(Seq("ephone", "aphone", "yphone"))
)
),
forwardToReplicas = Some(true),
replaceExistingSynonyms = Some(true)
),
Duration(100, "sec")
)
// print the response
println(response)// Initialize the client
let client = try SearchClient(appID: "ALGOLIA_APPLICATION_ID", apiKey: "ALGOLIA_API_KEY")
// Call the API
let response = try await client.saveSynonyms(
indexName: "<YOUR_INDEX_NAME>",
synonymHit: [
SynonymHit(objectID: "id1", type: SynonymType.synonym, synonyms: ["car", "vehicule", "auto"]),
SynonymHit(
objectID: "id2",
type: SynonymType.onewaysynonym,
synonyms: ["ephone", "aphone", "yphone"],
input: "iphone"
),
],
forwardToReplicas: true,
replaceExistingSynonyms: true
)
// print the response
print(response){
"taskID": 1514562690001,
"updatedAt": "2023-07-04T12:49:15Z"
}{
"message": "Invalid Application-Id or API-Key"
}{
"message": "Invalid Application-Id or API-Key"
}{
"message": "Invalid Application-Id or API-Key"
}{
"message": "Invalid Application-Id or API-Key"
}editSettingsAuthorizations
Your Algolia application ID.
Your Algolia API key with the necessary permissions to make the request. Permissions are controlled through access control lists (ACL) and access restrictions. The required ACL to make a request is listed in each endpoint's reference.
Path Parameters
Name of the index on which to perform the operation.
"ALGOLIA_INDEX_NAME"
Query Parameters
Whether changes are applied to replica indices.
Whether to replace all synonyms in the index with the ones sent with this request.
Body
Unique identifier of a synonym object.
"synonymID"
Synonym type.
synonym, onewaysynonym, altcorrection1, altcorrection2, placeholder, oneWaySynonym, altCorrection1, altCorrection2 "onewaysynonym"
Words to be matched in records.
["vehicle", "auto"]
Word or phrase to appear in query strings (for onewaysynonyms).
"car"
Placeholder token to be put inside records.
"<Street>"
Words or phrases considered equivalent.
["vehicle", "auto"]
Word or phrase to appear in query strings (for altcorrection1 and altcorrection2).
"car"
Response
OK
Response, taskID, and update timestamp.
Unique identifier of a task.
A successful API response means that a task was added to a queue.
It might not run immediately.
You can check the task's progress with the task operation and this task ID.
1514562690001
Date and time when the object was updated, in RFC 3339 format.
"2023-07-04T12:49:15Z"
Was this page helpful?