Skip to main content
This page documents an earlier version of the API client. For the latest version, see Batch indexing operations on one index.
Required ACL: depends on operations performed inside the batch This method lets you batch multiple indexing operations in one API request, such as adding or deleting records, potentially targeting multiple indices. Benefits:
  • Reduced latency. Only one network trip is required for multiple operations.
  • Data integrity. All operations inside the batch are executed atomically.
Instead of deleting 30 records then adding 20 new records 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 atomic reindexing using a temporary index.
When updating large numbers of records, be aware of the rate limitations on these processes and the impact on your analytics data. You’ll know you’ve reached the rate limit when you start receiving errors. This can only be resolved if you wait before sending any further indexing operations.

Examples

Batch write operations

  List<BatchOperation<Contact>> operations = new List<BatchOperation<Contact>>
  {
      new BatchOperation<Contact>
      {
        Action = BatchActionType.AddObject,
        IndexName = "index1",
        Body = new Contact { FirstName = "Jimmie", LastName = "Barninger" }
      },
      new BatchOperation<Contact>
      {
        Action = BatchActionType.UpdateObject,
        IndexName = "index1",
        Body = new Contact { ObjectID = "myID2", FirstName = "Max", LastName = "Barninger" }
      },
      new BatchOperation<Contact>
      {
        Action = BatchActionType.PartialUpdateObject,
        IndexName = "index1",
        Body = new Contact { ObjectID = "myID3", LastName = "McFarway" }
      },
      new BatchOperation<Contact>
      {
        Action = BatchActionType.PartialUpdateObjectNoCreate,
        IndexName = "index1",
        Body = new Contact { ObjectID = "myID4", LastName = "Warren" }
      },
      new BatchOperation<Contact>
      {
        Action = BatchActionType.DeleteObject,
        IndexName = "index2",
        Body = new Contact { ObjectID = "myID5" }
      }
  };

client.MultipleBatch(operations);

// Asynchronous
client.MultipleBatchAsync(operations);

Batch write operations and send extra HTTP headers

RequestOptions requestOptions = new RequestOptions
{
    Headers = new Dictionary<string,string>{ { "X-Algolia-User-ID", "user123" } }
};

  List<BatchOperation<Contact>> operations = new List<BatchOperation<Contact>>
  {
      new BatchOperation<Contact>
      {
        Action = BatchActionType.AddObject,
        IndexName = "index1",
        Body = new Contact { FirstName = "Jimmie", LastName = "Barninger" }
      },
      new BatchOperation<Contact>
      {
        Action = BatchActionType.AddObject,
        IndexName = "index1",
        Body = new Contact { FirstName = "Warren", LastName = "Speach" }
      }
  };

client.MultipleBatch(operations, requestOptions);

// Asynchronous
client.MultipleBatchAsync(operations, requestOptions);

Parameters

operations
operation[]
required
List of operations.
requestOptions
object
A mapping of request options to send along with the query.

Response

objectIDs
string[]
List of objectIDs affected by the batch of operations.
taskID
string[]
A list of taskIDs to use with the waitTask method. One for each index.

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 the getLogs method. Don’t rely on the order of properties—JSON objects don’t preserve key order.
JSON
{
  "objectIDs": [
    "myObjectID1",
    "myObjectID2"
  ],
  "taskID": {
    "index1": 29866710291
  }
}
I