# Elastic delete query

**URL:** <https://discuss.elastic.co/t/elastic-delete-query/226366>\
**Category:** Elasticsearch\
**Created:** [April 3, 2020, 8:50am UTC](https://discuss.elastic.co/t/elastic-delete-query/226366 "2020-04-03T08:50:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![niraj\_pandey](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/niraj_pandey/32/44034_2.png) [@niraj\_pandey](https://discuss.elastic.co/u/niraj_pandey)\
**Post date:** [April 3, 2020, 8:50am UTC](https://discuss.elastic.co/t/elastic-delete-query/226366/1 "2020-04-03T08:50:02Z")

</div>

Hi ,

I need to delete some data based on time from a index. Using below qury I am able to get all the data.

curl -XGET '[http://abc6:9200/data\*/\_search?pretty](http://abc6:9200/data*/_search?pretty)' -H 'Content-Type: application/json' -d' { "query":{ "bool":{ "must":[{ "match\_all":{} }, { "match\_phrase":{ "cluster":{ "query":"abc" } } },{ "range":{ "event\_time":{ "gte": "2020-03-02T00:00:00", "lte": "2020-03-02T23:59:59", "time\_zone": "America/Los\_Angeles", "format": "strict\_date\_optional\_time" } } }] }} }'

But my following Delete qeury not working , any idea ?

curl -XDELETE '[http://abc6:9200/data\*/\_delete](http://abc6:9200/data*/_delete)' -d' { "query":{ "bool":{ "must":[{ "match\_all":{} }, { "match\_phrase":{ "cluster":{ "query":"abc" } } },{ "range":{ "event\_time":{ "gte": "2020-03-02T00:00:00", "lte": "2020-03-02T23:59:59", "time\_zone": "America/Los\_Angeles", "format": "strict\_date\_optional\_time" } } }] }} }'

I am getting following error:

{"error":"Incorrect HTTP method for uri [/data\*/\_delete] and method [DELETE], allowed: [POST]","status":405}

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 3, 2020, 10:24am UTC](https://discuss.elastic.co/t/elastic-delete-query/226366/2 "2020-04-03T10:24:27Z")

</div>

The right command is explained in the documentation. Read [https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete-by-query.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete-by-query.html)

---

<div class="post-metadata">

**Author:** ![niraj\_pandey](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/niraj_pandey/32/44034_2.png) [@niraj\_pandey](https://discuss.elastic.co/u/niraj_pandey)\
**Post date:** [April 3, 2020, 11:17am UTC](https://discuss.elastic.co/t/elastic-delete-query/226366/3 "2020-04-03T11:17:43Z")

</div>

Thanks !!

After following the doc you shared I have deleted the data succesfully.

curl -XPOST '[http://abc6:9200/data\*/\_delete\_by\_query?pretty](http://abc6:9200/data*/_delete_by_query?pretty)' -H 'Content-Type: application/json' -d' { "query":{ "bool":{ "must":[{ "match\_all":{} }, { "match\_phrase":{ "cluster":{ "query":"abc" } } },{ "range":{ "event\_time":{ "gte": "2020-03-03T00:00:00", "lte": "2020-03-03T23:59:59", "time\_zone": "America/Los\_Angeles", "format": "strict\_date\_optional\_time" } } }] }} }'

---

<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:** [May 1, 2020, 11:17am UTC](https://discuss.elastic.co/t/elastic-delete-query/226366/4 "2020-05-01T11:17:50Z")

</div>

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