# DELETE api vs \_delete\_by\_query against index alias

**URL:** https://discuss.elastic.co/t/delete-api-vs-delete-by-query-against-index-alias/238439
**Category:** Elasticsearch
**Created:** [June 24, 2020, 10:52am UTC](https://discuss.elastic.co/t/delete-api-vs-delete-by-query-against-index-alias/238439 "2020-06-24T10:52:37Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![raulk89](https://avatars.discourse-cdn.com/v4/letter/r/2bfe46/32.png) [@raulk89](https://discuss.elastic.co/u/raulk89)
#### Post date: [June 24, 2020, 10:52am UTC](https://discuss.elastic.co/t/delete-api-vs-delete-by-query-against-index-alias/238439/1 "2020-06-24T10:52:37Z")

</div>

Hi

Elastic 6.8.4

When I have 2 indices, **A** and **B**. I have created alias **X** for these. For index B **is\_write\_index: true**  
Both of these indexes has doc with **\_id: 5**

When I do  
`DELETE /X/_doc/5`

Then the doc is deleted only from index **B** (I have tried deleting it multiple times, it does not get deleted from index **A** )

On the contrary, when I do **\_delete\_by\_query** against the alias name.

```
POST /X/_delete_by_query
{
  "query": {
    "match": {
      "_id": "5"
    }
  }
}

```

Then this does delete this doc from both indexes.

Is this intended behaviour that DELETE api does not delete all the docs from indexes that are defined for specific alias..?

Raul

---

<div class="post-metadata">

### Author: ![HenningAndersen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/henningandersen/32/48188_2.png) [@HenningAndersen](https://discuss.elastic.co/u/HenningAndersen)
#### Post date: [June 24, 2020, 11:07am UTC](https://discuss.elastic.co/t/delete-api-vs-delete-by-query-against-index-alias/238439/2 "2020-06-24T11:07:46Z")

</div>

@raulk89, yes, that is intended behavior.

The `DELETE /X/_doc/5` API is meant to delete a single document only. If your write alias did not have `is_write_index: true` on any of the indices (and still point to multiple indices), it would fail due to not being able to uniquely identify the doc to delete.

The request and response does not allow for multiple deletions. This makes it simple to use for the simple cases. For instance, the DELETE response includes information on the specific index the delete was done against as well as the version information for the document deleted.

`_delete_by_query` on the other hand runs a query against the alias and simply deletes all the resulting hits - against the specific indices returned in the search result.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [July 22, 2020, 11:07am UTC](https://discuss.elastic.co/t/delete-api-vs-delete-by-query-against-index-alias/238439/3 "2020-07-22T11:07:47Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
