Elastic delete query

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' -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' -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}

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

Thanks !!

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

curl -XPOST '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" } } } ] }} }'

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