DELETE api vs _delete_by_query against index alias


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


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

1 Like

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