curl
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"
}Synonyms
Create or replace synonyms
If a synonym with the objectID doesn’t exist, Algolia adds a new one. Otherwise, existing synonyms are replaced.
POST
/
1
/
indexes
/
{indexName}
/
synonyms
/
batch
curl
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"
}This operation is subject to indexing rate limits.
Required ACL:
editSettingsAuthorizations
Path Parameters
Query Parameters
Body
application/json
Word or phrase to appear in query strings (for onewaysynonyms).
Example:
"car"
Placeholder token to be put inside records.
Example:
"<Street>"
Word or phrase to appear in query strings (for altcorrection1 and altcorrection2).
Example:
"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.
Example:
1514562690001
Last modified on March 23, 2026
Was this page helpful?