> ## Documentation Index
> Fetch the complete documentation index at: https://algolia.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Delete objects

> Delete records from an index using their `objectID`.

export const Legacy = ({title, href}) => {
  return <Note>

    This page documents an earlier version of the API client.
    For the latest version, see <a href={href}>{title}</a>.

    </Note>;
};

<Legacy title="Delete records" href="/doc/libraries/sdk/methods/search/delete-objects" />

**Required ACL:** `deleteObject`

You can use two methods to delete records:

* `deleteObject` (this method), which uses `objectID` to identify records
* [`deleteBy`](/doc/libraries/sdk/v1/methods/delete-by), which uses `filters` to identify records.

Each record included in the batch [counts as one operation](https://support.algolia.com/hc/en-us/articles/18138875086865).
If you pass an `objectID` that doesn't exist, it still counts as an operation because Algolia doesn't know if the record exists when attempting the operation.

**Deleting all records in an index doesn't delete the index.**
To delete an index completely, including records, settings, synonyms, and rules, use the [`deleteIndex`](/doc/libraries/sdk/v1/methods/delete-index) method.
To delete a single record, use the [`deleteObject`](#delete-a-single-record) method.

<Info>
  When deleting large numbers of records be aware of the [rate limitations](/doc/guides/scaling/algolia-service-limits#application-record-and-index-limits) on these processes and the [impact on your analytics data](/doc/guides/sending-and-managing-data/manage-indices-and-apps/manage-indices/concepts/indices-analytics).
</Info>

## Examples

### Delete multiple records

<CodeGroup>
  ```cs C# theme={"system"}
  List<string> ids = new List<string> { "myID1", "myID2" };

  index.DeleteObjects(ids);

  // Asynchronous
  await index.DeleteObjectsAsync(ids);
  ```

  ```go Go theme={"system"}
  res, err := index.DeleteObjects(
    []string{"myID1", "myID2"},
  )
  ```

  ```java Java theme={"system"}
  index.deleteObjects(Arrays.asList("myID1", "myID2"));

  // Asynchronous
  index.deleteObjectsAsync(Arrays.asList("myID1", "myID2"));
  ```

  ```js JavaScript theme={"system"}
  index.deleteObjects(['myID1', 'myID2']).then(({ objectIDs }) => {
    console.log(objectIDs);
  });
  ```

  ```kotlin Kotlin theme={"system"}
  val objectIDS = listOf(ObjectID("myID1"), ObjectID("myID2"))

  index.deleteObjects(objectIDS)
  ```

  ```php PHP theme={"system"}
  $index->deleteObjects(["myID1", "myID2"]);
  ```

  ```python Python theme={"system"}
  index.delete_objects(['myID1', 'myID2'])
  ```

  ```ruby Ruby theme={"system"}
  index.delete_objects(['myID1', 'myID2'])
  ```

  ```scala Scala theme={"system"}
  client.execute {
    delete from "test1" objectIds Seq("myID1", "myID2")
  }
  ```

  ```swift Swift theme={"system"}
  index.deleteObjects(withIDs: ["myID1", "myID2"]) { result in
    if case .success(let response) = result {
      print("Response: \(response)")
    }
  }
  ```
</CodeGroup>

### Delete a single record

<CodeGroup>
  ```cs C# theme={"system"}
  index.DeleteObject("myID");

  // Asynchronous
  await index.DeleteObjectAsync("myID");
  ```

  ```go Go theme={"system"}
  res, err := index.DeleteObject("myID")
  ```

  ```java Java theme={"system"}
  index.deleteObject("myID");

  // Asynchronous
  index.deleteObjectAsync("myID");
  ```

  ```js JavaScript theme={"system"}
  index.deleteObject('myID').then(() => {
    // done
  });
  ```

  ```kotlin Kotlin theme={"system"}
  val objectID = ObjectID("myID1")

  index.deleteObject(objectID)
  ```

  ```php PHP theme={"system"}
  $index->deleteObject('myID');
  ```

  ```python Python theme={"system"}
  index.delete_object('myID')
  ```

  ```ruby Ruby theme={"system"}
  index.delete_object('myID')
  ```

  ```scala Scala theme={"system"}
  client.execute { delete from "myIndex" objectId "myId" }
  ```

  ```swift Swift theme={"system"}
  index.deleteObject(withID: "myID") { result in
    if case .success(let response) = result {
      print("Response: \(response)")
    }
  }
  ```
</CodeGroup>

## Parameters

<ParamField body="objectID" type="string" required>
  The objectID of the record to delete.
  (Required for the `deleteObject` method).
</ParamField>

<ParamField body="objectIDs" type="string[]" required>
  List of objectIDs to delete.
  (Required for the `deleteObjects` method).
</ParamField>

<ParamField body="requestOptions" type="object">
  A mapping of request options to send along with the query.
</ParamField>

## Response

<ResponseField name="objectIDs" type="string[]">
  List of the objectIDs of the deleted records.
</ResponseField>

<ResponseField name="taskID" type="integer">
  The task ID used with the [`waitTask`](/doc/libraries/sdk/v1/methods/wait-task) method.
</ResponseField>

### 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.

```jsonc JSON icon=braces theme={"system"}
{
  "objectIDs": [
    "myObjectID1",
    "myObjectID2"
  ],
  "taskID": 678,
}
```
