The generated API clients are a work in progress, you can also find our stable clients on the Algolia documentation.

Skip to main content

Delete Multiple Objects using Batch

In Algolia, you can delete multiple objects efficiently using the batch functionality. This guide will show you how to delete multiple objects at once.

Delete Multiple Objects

To delete multiple objects using batch, create a batch write params object that contains the array of delete requests. Each delete request should have the action set to deleteObject and the body containing the respective object ID. This allows you to define multiple delete operations within the requests array.

const objectIDs = ['1', '2', '3', '4', '5'];

const batchWriteParams = {
requests: objectIDs.map(id => ({
action: 'deleteObject',
body: {
objectID: id,
},
})),
};

await client.batch({ indexName, batchWriteParams });

By executing the above code, all the objects with the specified object IDs will be deleted from your index.

That’s it! You have successfully deleted multiple objects using batch.