Custom Batch
depends on operations performed inside the batch
ACL
$client->multipleBatch(array operations) $client->multipleBatch(array operations, array requestOptions)
About this method
We released a new version of the PHP API client in public beta. Read the beta documentation for more information.
We released a new version of the JavaScript API client in public beta. Read the beta documentation for more information.
We released a new version of the Java API client in public beta. Read the beta documentation for more information.
You’re currently reading the JavaScript API client v4 documentation. Check the migration guide to learn how to upgrade from v3 to v4. You can still access the v3 documentation.
You’re currently reading the Ruby API client v2 documentation. Check the migration guide to learn how to upgrade from v1 to v2. You can still access the v1 documentation.
Perform several indexing operations in one API call.
This method enables you to batch multiple different indexing operations in one API call, like add or delete objects, potentially targeting multiple indices.
You can use this method to:
- reduce latency - only one network trip is required for multiple operations
- ensure data integrity - all operations inside the batch will be executed atomically.
Instead of deleting 30 objects then adding 20 new objects in two operations, batching lets you combine both tasks in a single operation. This removes the time during which an index is in an inconsistent state and could be a great alternative to doing an atomic reindexing using a temporary index.
When batching of a large numbers of objects, or large sizes, be aware of the rate limit. You’ll know you’ve reached the rate limit when you start receiving errors on your indexing operations. This can only be resolved if you wait before sending any further indexing operations.
Examples
Read the Algolia CLI documentation for more information.
Batch write operations
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
$res = $client->multipleBatch(
[
[
'action' => 'addObject',
'indexName' => 'index1',
'body' => [
'firstname' => 'Jimmie',
'lastname' => 'Barninger'
]
],
[
'action' => 'updateObject',
'indexName' => 'index1',
'body' => [
'objectID' => 'myID2',
'firstname' => 'Max',
'lastname' => 'Barninger'
]
],
[
'action' => 'partialUpdateObject',
'indexName' => 'index1',
'body' => [
'objectID' => 'myID3',
'lastname' => 'McFarway'
]
],
[
'action' => 'partialUpdateObjectNoCreate',
'indexName' => 'index1',
'body' => [
'objectID' => 'myID4',
'firstname' => 'Warren'
]
],
[
'action' => 'deleteObject',
'indexName' => 'index2',
'body' => [
'objectID' => 'myID5'
]
]
]
);
Batch write operations and send extra HTTP headers
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
$operations = [
[
'action' => 'addObject',
'indexName' => 'index1',
'body' => [
'firstname' => 'Jimmie',
'lastname' => 'Barninger'
]
],
[
'action' => 'addObject',
'indexName' => 'index2',
'body' => [
'firstname' => 'Warren',
'lastname' => 'Speach'
]
]
];
$res = $client->multipleBatch($operations, [
'X-Forwarded-For' => '94.228.178.246'
]);
Parameters
operations
|
type: list of
Required
List of operation. Each operation is described by: |
requestOptions
|
type: key-value mapping
default: No requestOptions
Optional
A mapping of |
operations âž” operation
action
|
type: string
Required
Actions that need to be performed. It can be one of the following values:
|
||
indexName
|
type: string
Required
Index name to target. |
||
body
|
type: object
Required
The JSON object containing the information you need for the selected action. For example,
Copy
|
Response
This section shows the JSON response returned by the API. Since each language encapsulates this response inside objects specific to that language and/or implementation, the actual type in your language might differ from what’s written here. You can view the response in the logs (using the getLogs
method).
JSON format
1
2
3
4
5
6
7
8
9
{
"objectIDs": [
"myObjectID1",
"myObjectID2"
],
"taskID": {
"index1": 29866710291
}
}
objectIDs
|
list
List of objectIDs affected by the batch of operations. |
taskID
|
list
A list of taskIDs to use with the waitTask method. One for each index. |