Muthukumar Marichamy
Muthukumar Marichamy

Reputation: 1214

Elastic search query add 30 days in the value of attributes

I have the structure as below. I need to write the query to add 30 days from the "expiryDate" then check less than today date.

{
  _id: "100000001",
  name: "John",
  expiryDate: "30/07/2020"
}

Here, I need to check expirtyDate + 30 days < today date

Anyone help me to do the query.

Upvotes: 1

Views: 557

Answers (1)

Val
Val

Reputation: 217274

So you want to find the documents whose expiry date are within 30 days of the current date. You need to do it like this:

{
  "query": {
    "range": {
      "expiryDate": {
        "gte": "now-30d",
        "lte": "now"
      } 
    }
  }
}

Upvotes: 2

Related Questions