0

Its been observed that lte and gte both take lower bound values. how do I make it to take upper bound for lte and lower bound for gte??

This is how my query looks

{
  "from": 0,
  "size": 40,
  "query": {
    "filtered": {
      "filter": {
    "bool": {
      "should": [
        {
          "range": {
            "CreatedOn": {
              "lte": "201505",
              "gte": "201404",
              "format": "yyyyMM"
            }
          }
        }
      ]
    }
      }
    }
  }
}

The above query does not return me valid documents such as "2015-05-06T12:55:34.44", "2015-05-26T14:42:24.963" etc. It only returns "2015-05-01T11:42:24.963" from lte 201505

1 Answers1

0
  • 201404 means April 1st 2014
  • 201505 means May 1st 2015

This is the reason why you get that result. Elasticsearch "translates" in the background your query into a range one like 1396310400000 TO 1430524799999, meaning 01 Apr 2014 00:00:00 GMT TO 01 May 2015 23:59:59 GMT.

If you want everything between entire month of April 2014 and entire month of May 2015, then use this:

          "range": {
            "createdOn": {
              "lte": "201506||-1d/d",
              "gte": "201404",
              "format": "yyyyMM"
            }
          }
Andrei Stefan
  • 51,654
  • 6
  • 98
  • 89