addObject
Before using this method, set up transformation options on the search client.
To use this method, you must have only one Push to Algolia connector.
The API returns a 400 error if you have more than one Push connector,
or you use Collections and a Push connector.
For more information, see WithTransformation helper methods.
This helper method replaces all records in an index without interrupting ongoing searches.
It combines batch and copy/move index operations:
- Copy settings, synonyms, and rules to a temporary index.
- Add the records from the
objectsparameter to the temporary index. - Replace the original index with the temporary one.
INDEX_NAME_tmp_*
(replace INDEX_NAME with the name of your original index).
This method is subject to indexing rate limits and connector limits.
The response includes the results of the individual API requests.
Usage
var response = await client.ReplaceAllObjectsWithTransformationAsync(
"INDEX_NAME",
new List<Object>
{
new Dictionary<string, string> { { "objectID", "1" }, { "name", "Adam" } },
new Dictionary<string, string> { { "objectID", "2" }, { "name", "Benoit" } },
new Dictionary<string, string> { { "objectID", "3" }, { "name", "Cyril" } },
new Dictionary<string, string> { { "objectID", "4" }, { "name", "David" } },
new Dictionary<string, string> { { "objectID", "5" }, { "name", "Eva" } },
new Dictionary<string, string> { { "objectID", "6" }, { "name", "Fiona" } },
new Dictionary<string, string> { { "objectID", "7" }, { "name", "Gael" } },
new Dictionary<string, string> { { "objectID", "8" }, { "name", "Hugo" } },
new Dictionary<string, string> { { "objectID", "9" }, { "name", "Igor" } },
new Dictionary<string, string> { { "objectID", "10" }, { "name", "Julia" } },
},
3
);
final response = await client.replaceAllObjectsWithTransformation(
indexName: "INDEX_NAME",
objects: [
{
'objectID': "1",
'name': "Adam",
},
{
'objectID': "2",
'name': "Benoit",
},
{
'objectID': "3",
'name': "Cyril",
},
{
'objectID': "4",
'name': "David",
},
{
'objectID': "5",
'name': "Eva",
},
{
'objectID': "6",
'name': "Fiona",
},
{
'objectID': "7",
'name': "Gael",
},
{
'objectID': "8",
'name': "Hugo",
},
{
'objectID': "9",
'name': "Igor",
},
{
'objectID': "10",
'name': "Julia",
},
],
batchSize: 3,
);
response, err := client.ReplaceAllObjectsWithTransformation(
"INDEX_NAME",
[]map[string]any{
{"objectID": "1", "name": "Adam"},
{"objectID": "2", "name": "Benoit"},
{"objectID": "3", "name": "Cyril"},
{"objectID": "4", "name": "David"},
{"objectID": "5", "name": "Eva"},
{"objectID": "6", "name": "Fiona"},
{"objectID": "7", "name": "Gael"},
{"objectID": "8", "name": "Hugo"},
{"objectID": "9", "name": "Igor"},
{"objectID": "10", "name": "Julia"},
},
search.WithBatchSize(3),
)
if err != nil {
// handle the eventual error
panic(err)
}
ReplaceAllObjectsWithTransformationResponse response = client.replaceAllObjectsWithTransformation(
"INDEX_NAME",
Arrays.asList(
new HashMap() {
{
put("objectID", "1");
put("name", "Adam");
}
},
new HashMap() {
{
put("objectID", "2");
put("name", "Benoit");
}
},
new HashMap() {
{
put("objectID", "3");
put("name", "Cyril");
}
},
new HashMap() {
{
put("objectID", "4");
put("name", "David");
}
},
new HashMap() {
{
put("objectID", "5");
put("name", "Eva");
}
},
new HashMap() {
{
put("objectID", "6");
put("name", "Fiona");
}
},
new HashMap() {
{
put("objectID", "7");
put("name", "Gael");
}
},
new HashMap() {
{
put("objectID", "8");
put("name", "Hugo");
}
},
new HashMap() {
{
put("objectID", "9");
put("name", "Igor");
}
},
new HashMap() {
{
put("objectID", "10");
put("name", "Julia");
}
}
),
3
);
const response = await client.replaceAllObjectsWithTransformation({
indexName: 'cts_e2e_replace_all_objects_with_transformation_javascript',
objects: [
{ objectID: '1', name: 'Adam' },
{ objectID: '2', name: 'Benoit' },
{ objectID: '3', name: 'Cyril' },
{ objectID: '4', name: 'David' },
{ objectID: '5', name: 'Eva' },
{ objectID: '6', name: 'Fiona' },
{ objectID: '7', name: 'Gael' },
{ objectID: '8', name: 'Hugo' },
{ objectID: '9', name: 'Igor' },
{ objectID: '10', name: 'Julia' },
],
batchSize: 3,
});
var response =
client.replaceAllObjectsWithTransformation(
indexName = "INDEX_NAME",
objects =
listOf(
buildJsonObject {
put("objectID", JsonPrimitive("1"))
put("name", JsonPrimitive("Adam"))
},
buildJsonObject {
put("objectID", JsonPrimitive("2"))
put("name", JsonPrimitive("Benoit"))
},
buildJsonObject {
put("objectID", JsonPrimitive("3"))
put("name", JsonPrimitive("Cyril"))
},
buildJsonObject {
put("objectID", JsonPrimitive("4"))
put("name", JsonPrimitive("David"))
},
buildJsonObject {
put("objectID", JsonPrimitive("5"))
put("name", JsonPrimitive("Eva"))
},
buildJsonObject {
put("objectID", JsonPrimitive("6"))
put("name", JsonPrimitive("Fiona"))
},
buildJsonObject {
put("objectID", JsonPrimitive("7"))
put("name", JsonPrimitive("Gael"))
},
buildJsonObject {
put("objectID", JsonPrimitive("8"))
put("name", JsonPrimitive("Hugo"))
},
buildJsonObject {
put("objectID", JsonPrimitive("9"))
put("name", JsonPrimitive("Igor"))
},
buildJsonObject {
put("objectID", JsonPrimitive("10"))
put("name", JsonPrimitive("Julia"))
},
),
batchSize = 3,
)
$response = $client->replaceAllObjectsWithTransformation(
'INDEX_NAME',
[
['objectID' => '1',
'name' => 'Adam',
],
['objectID' => '2',
'name' => 'Benoit',
],
['objectID' => '3',
'name' => 'Cyril',
],
['objectID' => '4',
'name' => 'David',
],
['objectID' => '5',
'name' => 'Eva',
],
['objectID' => '6',
'name' => 'Fiona',
],
['objectID' => '7',
'name' => 'Gael',
],
['objectID' => '8',
'name' => 'Hugo',
],
['objectID' => '9',
'name' => 'Igor',
],
['objectID' => '10',
'name' => 'Julia',
],
],
3,
);
response = client.replace_all_objects_with_transformation(
index_name="INDEX_NAME",
objects=[
{
"objectID": "1",
"name": "Adam",
},
{
"objectID": "2",
"name": "Benoit",
},
{
"objectID": "3",
"name": "Cyril",
},
{
"objectID": "4",
"name": "David",
},
{
"objectID": "5",
"name": "Eva",
},
{
"objectID": "6",
"name": "Fiona",
},
{
"objectID": "7",
"name": "Gael",
},
{
"objectID": "8",
"name": "Hugo",
},
{
"objectID": "9",
"name": "Igor",
},
{
"objectID": "10",
"name": "Julia",
},
],
batch_size=3,
)
response = client.replace_all_objects_with_transformation(
"INDEX_NAME",
[
{objectID: "1", name: "Adam"},
{objectID: "2", name: "Benoit"},
{objectID: "3", name: "Cyril"},
{objectID: "4", name: "David"},
{objectID: "5", name: "Eva"},
{objectID: "6", name: "Fiona"},
{objectID: "7", name: "Gael"},
{objectID: "8", name: "Hugo"},
{objectID: "9", name: "Igor"},
{objectID: "10", name: "Julia"}
],
3
)
val response = Await.result(
client.replaceAllObjectsWithTransformation(
indexName = "INDEX_NAME",
objects = Seq(
JObject(List(JField("objectID", JString("1")), JField("name", JString("Adam")))),
JObject(List(JField("objectID", JString("2")), JField("name", JString("Benoit")))),
JObject(List(JField("objectID", JString("3")), JField("name", JString("Cyril")))),
JObject(List(JField("objectID", JString("4")), JField("name", JString("David")))),
JObject(List(JField("objectID", JString("5")), JField("name", JString("Eva")))),
JObject(List(JField("objectID", JString("6")), JField("name", JString("Fiona")))),
JObject(List(JField("objectID", JString("7")), JField("name", JString("Gael")))),
JObject(List(JField("objectID", JString("8")), JField("name", JString("Hugo")))),
JObject(List(JField("objectID", JString("9")), JField("name", JString("Igor")))),
JObject(List(JField("objectID", JString("10")), JField("name", JString("Julia"))))
),
batchSize = 3
),
Duration(100, "sec")
)
let response = try await client.replaceAllObjectsWithTransformation(
indexName: "INDEX_NAME",
objects: [
["objectID": "1", "name": "Adam"],
["objectID": "2", "name": "Benoit"],
["objectID": "3", "name": "Cyril"],
["objectID": "4", "name": "David"],
["objectID": "5", "name": "Eva"],
["objectID": "6", "name": "Fiona"],
["objectID": "7", "name": "Gael"],
["objectID": "8", "name": "Hugo"],
["objectID": "9", "name": "Igor"],
["objectID": "10", "name": "Julia"],
],
batchSize: 3
)
Parameters
- Go
- Java
- JavaScript
- PHP
- Python
string
required
Name of the index in which to replace records.
[]map[string]any
required
Records that replace the existing records in your index.
replaceAllObjectsOption
Functional options to provide extra arguments.
Show available functions
Show available functions
function
Signature:
func(scopes []ScopeType) replaceAllObjectsOptionScopes to include in the replacement operation.
Can be one or more of settings, synonyms, or rules.
For more details, see Scope types.function
Signature:
func(batchSize int) chunkedBatchOptionNumber of records to process in one batch.
The default batch size is 1,000.function
Signature:
func(withWaitForTasks bool) chunkedBatchOptionWhether to wait until all batch requests are done.function
Signature:
func(key string, value string) requestOptionSets extra header parameters for this request.
To learn more, see request options.function
Signature:
func(key string, value string) requestOptionSets extra query parameters for this request.
To learn more, see request options.String
required
Name of the index in which to replace records.
Iterable<T>
required
Records that replace the existing records in your index.
Type parameter
required
The model of your index’s records.
List<ScopeType>
required
Scopes to include in the replacement operation.
Can be one or more of
settings, synonyms, or rules.
For more details, see Scope types.int
required
Number of records to process in one batch.
RequestOptions
Additional request options.
string
required
Name of the index in which to replace records.
Record<string,unknown>[]
required
Records that replace the existing records in your index.
string[]
required
Scopes to include in the replacement operation.
number
default:1000
Number of records to process in one batch.
RequestOptions
Additional request options.
string
required
Name of the index in which to replace records.
array
required
Records that replace the existing records in your index.
int
default:1000
Number of records to process in one batch.
array
required
Scopes to include in the replacement operation.
array
Additional request options.
str
required
Name of the index in which to replace records.
list[dict]
required
Records that replace the existing records in your index.
list[str]
required
Scopes to include in the replacement operation.
int
default:1000
Number of records to process in one batch.
dict | RequestOptions
Additional request options.