Alexander Nikolov
Alexander Nikolov

Reputation: 1979

elasticsearch - delete by query plugin, how to delete all records with date_time before today?

Following delete by query plugin documentation I have managed to delete records from my elasticseatch server with this simple query:

{
 "query": {
    "term": {
      "field1": "value1"
    } 
  }
}

Now, I have field date_time. What I would like to achieve is to delete all records which have date_time value before today (date_time < today ). There is no information in the docs about more complex delete queries. Is this possible ?

Upvotes: 0

Views: 523

Answers (1)

Val
Val

Reputation: 217274

You can simply use a range query and some date math like this:

{
 "query": {
    "range": {
      "date_time": {
        "lt" : "now/d"
      } 
    } 
  }
}

Upvotes: 1

Related Questions