hema
hema

Reputation: 1

How to write a elasticsearch query for searching document with "someDateField is before today-28 days/2 months/1 year"?

I have created this query to search for documents where empId is "XXXXXX" and joiningDate is before now (today's date).

GET employees/_search
{
  "query": {
    "bool": {
      "filter": [
        {
          "term": {
            "empId": "XXXXXX"
          }
        },
        {
          "range": {
            "joiningDate": {
              "lte": "now"
            }
          }
        }
      ]
    }
  }
}

I want help in modifying it to have the joiningDate condition as below joiningDate is before now-10 days (today's date-10 days)

Upvotes: 0

Views: 37

Answers (1)

Rafiqul Islam
Rafiqul Islam

Reputation: 225

{
"query":{
    "bool":{
        "filter":[
            {
                "term":{
                    "empId":"XXXXXX"
                }
            },
            {
                "range":{
                    "joiningDate":{
                        "gte":"now-10d/d",
                        "lt":"now/d"
                    }
                }
            }
        ]
    }
}

}

Upvotes: 1

Related Questions