Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete records from Elasticsearch by query

I am trying to delete specific date records from Elasticsearch. My query is the following:

curl -XDELETE 'http://localhost:9200/twitter/twit/_query' -d '
{
    "filter" : {
            "range" : {
                "date_time" : { "from" : "2012-10-01 00:00:01", "to" : "2013-05-01 11:59:59"}
            }
        }
}'

but it is not deleting any records. so it is correct one or are there some other methods to delete records.

like image 919
uttam palkar Avatar asked Jul 16 '13 12:07

uttam palkar


People also ask

How do I delete a record in Elasticsearch?

You use DELETE to remove a document from an index. You must specify the index name and document ID. You cannot send deletion requests directly to a data stream. To delete a document in a data stream, you must target the backing index containing the document.

How do I delete data from OpenSearch?

The ID of the document to delete. Only perform the delete operation if the document's version number matches the specified number. Only perform the delete operation if the document has the specified primary term. If true, OpenSearch refreshes shards to make the delete operation available to search results.

How do I delete a specific index in Elasticsearch?

To delete the index, you must roll over the data stream so a new write index is created. You can then use the delete index API to delete the previous write index.

Does deleting Elasticsearch index delete data?

Yes, deleting the index, deletes all the data in that index.


1 Answers

Prior to 1.0, the delete by query does not use filters. The syntax goes directly to what is the "query" block in the search API. You need to use the range query instead.

curl -XDELETE 'http://localhost:9200/twitter/twit/_query' -d '
{
    "range" : {
        "date_time" : { "from" : "2012-10-01 00:00:01", "to" : "2013-05-01 11:59:59"}
    }
}'
like image 98
Louis-Philippe Huberdeau Avatar answered Sep 22 '22 08:09

Louis-Philippe Huberdeau