Elasticsearch Delete By Query

Opster Team

Last updated: Mar 8, 2023

| 1 min read

In addition to reading this guide, we recommend you run the Elasticsearch Health Check-Up. It will detect issues and improve your Elasticsearch performance by analyzing your shard sizes, threadpools, memory, snapshots, disk watermarks and more.

The Elasticsearch Check-Up is free and requires no installation.

Before you begin reading this guide, we recommend you try running the Elasticsearch Error Check-Up which analyzes 2 JSON files to detect many configuration errors.

To understand other Elasticsearch APIs like delete-by-query and detect issues to improve your Elasticsearch performance, try  AutoOps for Elasticsearch. AutoOps diagnoses problems by analyzing hundreds of metrics collected by a lightweight agent and offers guidance for resolving them.

Overview

Delete-by-query is an Elasticsearch API, which was introduced in version 5.0 and provides functionality to delete all documents that match the provided query. In lower versions, users had to install the Delete-By-Query plugin and use the DELETE /_query endpoint for this same use case.

What it is used for

This API is used for deleting all the documents from indices based on a query. Once the query is executed, Elasticsearch runs the process in the background to delete all the matching documents so you don’t have to wait for the process to be completed.

Examples

Delete all the documents of an index without deleting the mapping and settings:

POST /my_index/_delete_by_query?conflicts=proceed&pretty
{
  "query": {
    "match_all": {}
  }
}

The conflict parameter in the request is used to proceed with the request even in the case of version conflicts for some documents. The default conflict behavior is to abort the request altogether.

Notes

  • A long-running delete_by_query can be terminated using _task API.
  • Inside the query body, you can use the same syntax for queries that are available under the _search API.

Common problems

Elasticsearch takes a snapshot of the index when you hit delete by query request and uses the _version of the documents to process the request. If a document gets updated in the meantime, it will result in a version conflict error and the delete operation will fail.


Related log errors to this ES concept


Exception trying to setParsedQuery
Error when trying to query fileLength
Tried to query fileLength but file is gone
Unable to execute the graph query
Unexpected error creating default query
OnQueryPhase listener failed
OnPreQueryPhase listener failed
DeleteByQuery for indices timed out.
failures and conflicts encountered while running DeleteByQuery on indices .
Failed to add query
Failed to add query parser returned null
Scroll request failed; scrolling document(s) is stopped

< Page: 1 of 2 >

Watch product tour

Try AutoOps to find & fix Elasticsearch problems

Analyze Your Cluster
Skip to content