Does date-format of ES7.5.2 not support YYYY?

I created a field named "created" in the index as shown below:

"created": {
    "type": "date",
    "format": "YYYY-MM-dd'T'HH:mm:ss'Z'"
}

When I used the range method for querying, I got unexpected results. There is a document in Elasticsearch (ES) with a value of "2023-05-24T06:00:33Z" for the "created" field. However, when I queried with "range lt 2024-01-01T00:00:00Z", it failed to retrieve that document correctly.

To investigate the issue, I added the "explain" parameter to the query. Here is my statement:

{
  "explain": true,
  "query": {
    "bool": {
      "must": [
        {
          "range": {
            "created": {
              "lt": "2023-05-25T00:00:00Z"
            }
          }
        }
      ]
    }
  }
}

The unexpected result in the returned explanation is: "created:[-9223372036854775808 TO 12441599999]". It appears that the value 12441599999 corresponds to 1970-05-25 07:59:59.

However, when I changed "YYYY" to "yyyy" in the mappings, everything worked correctly.

Yes, there is a differenece between YYYY and yyyy in Java date formats, as explained in this blog post.

TKS.
I read the above blog and the problem he mentioned only appears at the beginning and end of the year. In fact, the problem I have is that I can't parse the year when I range.

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