How to Search and Delete Specific Documents in Elasticsearch [curl Edition]

Tadashi Shigeoka ·  Thu, August 12, 2021

I’ll introduce how to search and delete specific documents in Elasticsearch using curl.

Background: Want to Delete Specific Documents in Elasticsearch with curl

I wanted to delete specific documents in Elasticsearch using curl, so I researched and practiced it.

Prerequisites

  • Elasticsearch version 7.10

Search Specific Documents with POST /target/_search

Search API | Elasticsearch Guide [7.x] | Elastic

curl \\
-H "Content-Type: application/json" \\
-XPOST \\
"$ES_HOST/products/_search" \\
-d '{ "query": { "match": { "id": "1" } } }'

Delete Specific Documents with POST /target/_delete_by_query

Delete by query API | Elasticsearch Guide [7.x] | Elastic

curl \\
-H "Content-Type: application/json" \\
-XPOST \\
"$ES_HOST/products/_delete_by_query" \\
-d '{ "query": { "match": { "id": "1" } } }'

That’s all from the Gemba.