Strange results with lte range comparison for dates in ES 6.5.0

Hello,

I am trying to add a filter to some of my queries to make sure my results are contained in a specific date interval. My complete final query (executed in kibana) looks like this:

    {
       "query":{
          "bool":{
             "should":[
                {
                   "exists":{
                      "field":"content.kws.piscine"
                   }
                }
             ],
             "filter": [
            {
              "bool": {
                "minimum_should_match": 2,
                "should": [
                  {
                    "range": {
                      "content.dates.dateEnd": {
                        "gte": "20060101T000000"
                      }
                    }
                  },
                  {
                    "bool": {
                      "must_not": {
                        "exists": {
                          "field": "content.dates.dateEnd"
                        }
                      }
                    }
                  },
                  {
                    "range": {
                      "content.dates.dateBegin": {
                        "lte": "20060101T000000"
                      }
                    }
                  },
                  {
                    "bool": {
                      "must_not": {
                        "exists": {
                          "field": "content.dates.dateBegin"
                        }
                      }
                    }
                  }
                ]
              }
            }
          ]
          }
       }
    }

I added clauses because I also want to return cases where the begin date and/or end date are not present. I have struggled to make it work for quite some time, and finally decided to break it into small pieces, trying to obtain results step by step. I discovered something really strange with this:

    {
       "query":{
          "bool":{
             "should":[
                {
                   "exists":{
                      "field":"content.kws.piscine"
                   }
                }
             ],
             "filter": [
            {
              "bool": {
                "minimum_should_match": 1,
                "should": [
                  {
                    "range": {
                      "content.dates.dateBegin": {
                        "lte": "20060101T000000"
                      }
                    }
                  }
                ]
              }
            }
          ]
          }
       }
    }

I made tests with this set of dates (in content):

        "dates" : [
          {
            "dateEnd" : "20040101T000000"
          },
          {
            "dateBegin" : "20060101T000000",
            "dateEnd" : "20060101T000000"
          }
        ]

I had no problem at all with the gte operator in range alone with the same query, but the lte operator gives no result, despite the beginning date of the document being rigorously equal to the date of the query.

I was wondering if I did something wrong, or missed something specific. It seems to me that the equal part of the lte operator is not working in ES 6.5.0 (other tests with dates greater or lower gave the expected results), but I think that's a low probability.

I managed to solve my problem. I was just not using a valid date format for elasticsearch 6.5, I forgot to add the time zone. The correct format was "yyyyMMdd'T'HHmmssZ", and with this everything worked fine.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.