Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete data older than 10 days in elasticsearch

I am new to elasticsearch and I want to delete documents in my elasticsearch index which are older than 10 days. I want to keep only last 10 days of data.So is there any way to delete last 11nth day index automatically. What I have tried..

DELETE logstash-*/_query
{
 "query": {
   "range": {
     "@timestamp": {
       "lte": "now-10d"
      }
    }
  }
}

Error I'm getting while running on kibana dev tools

{
"error": "Incorrect HTTP method for uri [/logstash-*/_query?pretty] and method [DELETE], 
allowed: [POST]",
"status": 405
}

Please help to resolve this issues.

like image 997
Kavya Avatar asked Jan 26 '23 20:01

Kavya


1 Answers

You need to leverage the Delete by Query Endpoint, like this:

use POST           use this endpoint
 |                      |
 V                      V
POST logstash-*/_delete_by_query
{
 "query": {
   "range": {
     "@timestamp": {
       "lte": "now-10d"
      }
    }
  }
}
  ^
  |
the query part is fine !!
like image 52
Val Avatar answered Jan 28 '23 10:01

Val