Elasticsearch OpenSearch Delete By Query

Average Read Time

1 Mins

Elasticsearch OpenSearch Delete By Query

Opster Team

Sep 11, 2022

Average Read Time

1 Mins


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.

To manage all aspects of your OpenSearch operation, you can use Opster’s Management Console (OMC). The OMC makes it easy to orchestrate and manage OpenSearch in any environment. Using the OMC you can deploy multiple clusters, configure node roles, scale cluster resources, manage certificates and more – all from a single interface, for free. Check it out here.

Run the Elasticsearch check-up to receive recommendations like this:

checklist Run Check-Up
error

The following configuration error was detected on node 123...

error-img

Description

This error can have a severe impact on your system. It's important to understand that it was caused by...

error-img

Recommendation

In order to resolve this issue and prevent it from occurring again, we recommend that you begin by changing the configuration to...

1

X-PUT curl -H "Content-Type: application/json" [customized recommendation]

Overview

Delete-by-query is an OpenSearch 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, OpenSearch 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

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



Run the Check-Up to get a customized report like this:

Analyze your cluster
Skip to content