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

> Delete records matching a filter (including geo filters).

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 matching a filter" href="/doc/libraries/sdk/methods/search/delete-by" />

**Required ACL:** `deleteIndex`

* The filter must be included in your [`attributesForFaceting`](/doc/api-reference/api-parameters/attributesForFaceting).
  For more information, see [Define filterable attributes](/doc/guides/managing-results/refine-results/filtering#define-filterable-attributes).

* This operation counts as 1 operation, even if you delete more than one record.

* This method is subject to [rate-limiting](https://support.algolia.com/hc/en-us/articles/4406981897617).
  If you get errors when using this method, check if you're over the rate limit and wait before sending further indexing requests.

  * If you have more than 100 pending requests, your requests will be throttled.
  * If you have more than 1,000 pending requests pending, further requests will be rejected.

**You should only use this method if you can't get a list of object IDs of the records you want to delete.**
It's more efficient to get a list of object IDs with the [`browse`](/doc/libraries/sdk/v1/methods/browse) method,
and then delete the records using [`deleteObjects`](/doc/libraries/sdk/v1/methods/delete-objects).
For more information, see [Should I use the `deleteBy` method for deleting records matching a query?](https://support.algolia.com/hc/en-us/articles/16385098766353-Should-I-use-the-deleteby-method-for-deleting-records-matching-a-query-)

### Limitations

* The `deleteBy` operation can't be run in parallel.
* This method rejects empty filters or queries.

<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 records by filter

<CodeGroup>
  ```cs C# theme={"system"}
  var query = new Query { Filters = "category:cars", AroundLatLng = "40.71, -74.01" };

  index.DeleteBy(query);

  // Asynchronous
  await index.DeleteByAsync(query);
  ```

  ```go Go theme={"system"}
  res, err := index.DeleteBy(
      opt.Filters("category:cars"),
      opt.AroundLatLng("40.71, -74.01"),
  )
  ```

  ```java Java theme={"system"}
  Query query = new Query("query")
    .setFilters("category:cars")
    .setAroundLatLng("40.71, -74.01")

  // Sync version
  index.deleteBy(query);

  // Async version
  index.deleteByAsync(query);
  ```

  ```js JavaScript theme={"system"}
  index.deleteBy({
    filters: 'category:cars',
    aroundLatLng: '40.71, -74.01'
  }).then(() => {
    // done
  });
  ```

  ```kotlin Kotlin theme={"system"}
  val query = DeleteByQuery(
      filters = "category:car",
      aroundLatLng = Point(40.71f, -74.01f)
  )

  index.deleteObjectsBy(query)
  ```

  ```php PHP theme={"system"}
  $index->deleteBy([
    'filters' => 'category:cars',
    'aroundLatLng' => '40.71, -74.01'
    /* add any filter parameters */
  ]);
  ```

  ```python Python theme={"system"}
  index.delete_by({
    'filters': 'category:cars',
    'aroundLatLng': '40.71, -74.01'
  })
  ```

  ```ruby Ruby theme={"system"}
  params = {
    filters: 'category:cars',
    aroundLatLng: '40.71, -74.01'
  }
  index.delete_by(params)
  ```

  ```scala Scala theme={"system"}
  delete from "testDeleteBy" by Query(
    filters = Some("price > 10"),
    aroundLatLng = Some(
      AroundLatLng("40.71, -74.01")
    )
  )
  ```

  ```swift Swift theme={"system"}
  var query = DeleteByQuery()

  query.filters = "category:cars"
  query.aroundLatLng = .init(latitude: 40.71, longitude: -74.01)

  index.deleteObjects(byQuery: query) { result in
    if case .success(let response) = result {
      print("Response: \(response)")
    }
  }
  ```
</CodeGroup>

### Delete records by filter and send extra HTTP headers

<CodeGroup>
  ```cs C# theme={"system"}
  var query = new Query { Filters = "category:cars", AroundLatLng = "40.71, -74.01" };

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

  index.DeleteBy(query, requestOptions);

  // Asynchronous
  await index.DeleteByAsync(query, requestOptions);
  ```

  ```go Go theme={"system"}
  res, err := index.DeleteBy(
      opt.Filters("category:cars"),
      // Add any filter parameter
      opt.ExtraHeaders(map[string]string{"X-Algolia-User-ID": "userID2"}),
  )
  ```

  ```java Java theme={"system"}
  RequestOptions requestOptions = 
    new RequestOptions().addExtraHeader("X-Algolia-User-ID", "user123");

  // Sync version
  Query query = /* any filter parameters */;
  index.deleteBy(query, requestOptions);

  // Async version
  Query query = /* any filter parameters */;
  index.deleteByAsync(query, requestOptions);
  ```

  ```js JavaScript theme={"system"}
  const params = {
    'filters': 'category:cars',
    'aroundLatLng': '40.71, -74.01'
    /* add any filter parameters */
  };

  index.deleteBy(params, {
    headers: {
      'X-Algolia-User-ID': 'user123'
    }
  }).then(() => {
    // done
  });
  ```

  ```kotlin Kotlin theme={"system"}
  val query = DeleteByQuery(
      filters = "category:car",
      aroundLatLng = Point(40.71f, -74.01f)
  )
  val requestOptions = requestOptions {
      headerAlgoliaUserId(UserID("user123"))
  }

  index.deleteObjectsBy(query, requestOptions)
  ```

  ```php PHP theme={"system"}
  $params = [
    'filters' => 'category:cars',
    'aroundLatLng' => '40.71, -74.01'
    /* add any filter parameters */
  ];

  $index->deleteBy($params, [
    'X-Algolia-User-ID' => 'user123'
  ]);
  ```

  ```python Python theme={"system"}
  params = {
    # any filter parameters
  }

  index.delete_by(params, {
      'X-Algolia-User-ID': 'user123'}
  )
  ```

  ```ruby Ruby theme={"system"}
  params = {
    filters: 'category:cars'
  }

  index.delete_by(params, {
    headers: {
      'X-Algolia-User-ID': 'user123'
    }
  })
  ```

  ```scala Scala theme={"system"}
  delete from "testDeleteBy" by Query(filters = Some("price > 10"))
    options RequestOptions(
    ` extraHeaders = Some(Map("X-Algolia-User-ID" => "user123"))
    )
  ```

  ```swift Swift theme={"system"}
  var requestOptions = RequestOptions()
  requestOptions.headers["X-Algolia-User-ID"] = "user123"

  var query = DeleteByQuery()

  query.filters = "category:cars"
  query.aroundLatLng = .init(latitude: 40.71, longitude: -74.01)

  index.deleteObjects(byQuery: query, requestOptions: requestOptions) { result in
    if case .success(let response) = result {
      print("Response: \(response)")
    }
  }
  ```
</CodeGroup>

## Parameters

<ParamField body="filterParameters" type="object" required>
  An object with one or more of the following parameters:

  * [`filters`](/doc/api-reference/api-parameters/filters)
  * [`facetFilters`](/doc/api-reference/api-parameters/facetFilters)
  * [`numericFilters`](/doc/api-reference/api-parameters/numericFilters)
  * [`tagFilters`](/doc/api-reference/api-parameters/tagFilters)
  * [`aroundLatLng`](/doc/api-reference/api-parameters/aroundLatLng) and [`aroundRadius`](/doc/api-reference/api-parameters/aroundRadius) (these two need to be used together)
  * [`insideBoundingBox`](/doc/api-reference/api-parameters/insideBoundingBox)
  * [`insidePolygon`](/doc/api-reference/api-parameters/insidePolygon)
</ParamField>

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

## Response

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

<ResponseField name="updatedAt" type="string">
  Date at which the indexing job has been created.
</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"}
{
  "updatedAt": "2017-12-29T17:34:12.902Z",
  "taskID": 678,
}
```
