Delete objects

Required API Key: any key with the deleteObject ACL
Method signature
$index->deleteObjects(objectIds)
$index->deleteObjects(objectIds, requestOptions)

// delete a single object
$index->deleteObject(objectID)
$index->deleteObject(objectID, requestOptions)
Method signature
index.delete_objects(objectIds)
index.delete_objects(objectIds, request_options=requestOptions)

# delete a single object
index.delete_object(objectID)
index.delete_object(objectID, request_options=requestOptions)
Method signature
index.deleteObjects(objectIds, callback)

index.deleteObject(objectID, callback) // delete a single object
Method signature
index.delete_objects(objectIds)
index.delete_objects(objectIds, request_options=requestOptions)

# delete a single object
index.delete_object(objectID)
index.delete_object(objectID, request_options=requestOptions)
Method signature
index.deleteObjects(withIDs: objectIDs, completionHandler)
index.deleteObjects(
  withIDs: objectIDs,
  requestOptions: requestOptions,
  completionHandler
)

// delete a single object
index.deleteObject(withID: objectID, completionHandler)
index.deleteObject(
  withID: objectID,
  requestOptions: requestOptions,
  completionHandler
)

Method signature
index.deleteObjectsAsync(objectIDs, completionHandler);
index.deleteObjectsAsync(objectIDs, requestOptions, completionHandler);

// delete a single object
index.deleteObjectAsync(objectID, completionHandler);
index.deleteObjectAsync(objectID, requestOptions, completionHandler);
Method signature
index.DeleteObjects(objectIds);
index.DeleteObjects(objectIds, requestOptions);

// delete a single object
index.DeleteObject(objectID);
index.DeleteObject(objectID, requestOptions);
Method signature
index.deleteObjects(objectIds);
index.deleteObjects(objectIds, requestOptions);

// delete a single object
index.deleteObject(objectID);
index.deleteObject(objectID, requestOptions);
Method signature
index.DeleteObjects(objectIDs)
index.DeleteObjectsWithRequestOptions(objectIDs, requestOptions)

// delete a single object
index.DeleteObject(objectID)
index.DeleteObjectWithRequestOptions(objectID, requestOptions)
Method signature
delete from "index_name" objectIds objectIDs
delete from "index_name" objectIds objectIDs options requestOptions

// delete a single object
delete from "index_name" objectId objectID
delete from "index_name" objectId objectID options requestOptions

About this method

Remove objects from an index using their object ids.

This method enables you to remove one or more objects from an index.

There are 2 methods available to delete objects:

  • this one, which uses an objectID to identify objects
  • and delete by, which uses filters to identify objects

Note: This method also has a singular version.

Examples

Delete multiple objects using their objectIDs

<?php
$index->deleteObjects(["myID1", "myID2"]);
index.delete_objects(['myID1', 'myID2'])
index.deleteObjects(['myID1', 'myID2'], function(err, content) {
  if (err) throw err;

  console.log(content);
});
index.delete_objects(["myID1", "myID2"])
index.deleteObjects(withIDs: ["myID1", "myID2"])
index.deleteObjectsAsync(Arrays.asList("myID1", "myID2"), null);
List<string> ids = new List<string>();

ids.Add(@"myID1");
ids.Add(@"myID2");

var res = index.DeleteObjects(ids);

// Asynchronous
// var res = await index.DeleteObjectsAsync(ids);

System.Diagnostics.Debug.WriteLine(res);
// Sync & Async version
index.deleteObjects(Arrays.asList("myID1", "myID2"));
res, err := index.DeleteObjects(
  []string{"myID1", "myID2"},
)
client.execute {
  delete from "test1" objectIds Seq("1", "2")
}

Delete a single object

<?php
$index->deleteObject('myID');
index.delete_object('myID')
index.deleteObject('myID', function(err, content) {
  if (err) throw err;

  console.log(content);
});
index.delete_object("myID")
index.deleteObject(withID: "myID")
index.deleteObjectAsync("myID", null);
index.DeleteObject("myID");

// Asynchronous
// await index.DeleteObjectAsync("myID");
// Sync & Async version
index.deleteObject("myID");
res, err := index.DeleteObject("myID")
client.execute { delete from "myIndex" objectId "myId" }

Delete multiple objects and send extra http headers

<?php
$objectIDs = [/* objectIDs */];

$index->deleteObjects($objectIDs, [
  'X-FORWARDED-FOR' => '94.228.178.246'
]);
extra_headers = {
  'X-FORWARDED-FOR': '94.228.178.246'
}

object_ids = []

index.delete_objects(objects_ids, extra_headers)
client.setExtraHeader('X-FORWARDED-FOR', '94.228.178.246');
index.deleteObjects(['myID1', 'myID2'], function(err, content) {
  if (err) throw err;

  console.log(content);
});
request_options = RequestOptions({'algoliaUserID': 'user123'})
objectIDs = [
  # objectIDs
]
index.delete_objects(objectIDs, request_options=request_options)
let requestOptions = RequestOptions()
requestOptions.headers["X-Algolia-User-ID"] = "user123"

index.deleteObject(withID: "myID", requestOptions: requestOptions)
index.deleteObjectsAsync(
  Arrays.asList("myID1", "myID2"),
  new RequestOptions()
    .setHeader("X-Algolia-User-ID", "94.228.178.246"),
  null
);
RequestOptions requestOptions = new RequestOptions();
requestOptions.AddExtraHeader("X-Algolia-User-ID", "user123");

index.DeleteObject("myID", requestOptions);

// Asynchronous
// await index.DeleteObjectAsync("myID", requestOptions);
// Sync & Async version
index.deleteObjects(
  Arrays.asList("myID1", "myID2"),
  new RequestOptions().addExtraHeader("X-Algolia-User-ID", "user123")
);
opts := &algoliasearch.RequestOptions{
  ExtraHeaders: map[string]string{
    "X-Algolia-User-ID": "userID2",
  },
}

res, err := index.DeleteObjects(
  []string{"myID1", "myID2"},
  opts,
)
client.execute {
  delete from "test1" objectIds Seq("1", "2")
   options RequestOptions(
    extraHeaders = Some(Map("X-Algolia-User-ID" => "user123"))
  )
}

Parameters

objectIDs
type: list
Required

List of objectIDs to delete.

requestOptions
type: key value mapping
Optional
default: No request options

A mapping of request options to send along with the query.

objectID
type: integer|string
Required

The objectID of the object to delete.

Response

In this section we document the JSON response returned by the API. Each language will encapsulate this response inside objects specific to the language and/or the implementation. So the actual type in your language might differ from what is documented.

JSON format

{
  "objectIDs": [
    "myObjectID1",
    "myObjectID2"
  ],
  "taskID": 678,
}
objectIDs
list

List of the objectIDS of the deleted objects.

taskID
integer

The taskID used with the waitTask method.

Php small white
PHP
Ruby small white
Ruby
Javascript small white
JavaScript
Python small white
Python
Swift small white
iOS
Android small white
Android
Csharp small white
C#
Java small white
Java
Go small white
Go
Scala small white
Scala
Php small white
PHP
Ruby small white
Ruby
Javascript small white
JavaScript
Python small white
Python
Swift small white
iOS
Android small white
Android
Csharp small white
C#
Java small white
Java
Go small white
Go
Scala small white
Scala