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.