Elasticsearch version: 7.6 — 7.10
JVM version:
openjdk version "1.8.0_212"
OpenJDK Runtime Environment (build 1.8.0_212-b04)
OpenJDK 64-Bit Server VM (build 25.212-b04, mixed mode)
OS version: Linux
Description of the problem including expected versus actual behavior:
I have an index with a nullable date field. When I query items sorted by the field and specify size which equals total hits count, I get error:
{
"type": "response_handler_failure_transport_exception",
"reason": "java.time.DateTimeException: Field Year cannot be printed as the value 292278994 exceeds the maximum print width of 4"
}
Steps to reproduce:
PUT /bug-reproduce
{
"mappings": {
"properties": {
"date": {
"type": "date",
"format": "basic_date_time_no_millis"
}
}
},
"settings": {
"index": {
"number_of_shards": "1",
"number_of_replicas": "0"
}
}
}
PUT /bug-reproduce/_doc/1
{
"date": "20201202T190000Z"
}
PUT /bug-reproduce/_doc/2
{
"date": null
}
POST /bug-reproduce/_search
{
"size": 2,
"sort": [
{
"date": {}
}
]
}
{
"error":{
"root_cause":[
{
"type":"response_handler_failure_transport_exception",
"reason":"java.time.DateTimeException: Field Year cannot be printed as the value 292278994 exceeds the maximum print width of 4"
}
],
"type":"search_phase_execution_exception",
"reason":"all shards failed",
"phase":"query",
"grouped":true,
"failed_shards":[
{
"shard":0,
"index":"bug-reproduce",
"node":"nyQL21NNT2KkEcJCEahP1Q",
"reason":{
"type":"response_handler_failure_transport_exception",
"reason":"java.time.DateTimeException: Field Year cannot be printed as the value 292278994 exceeds the maximum print width of 4",
"caused_by":{
"type":"date_time_exception",
"reason":"Field Year cannot be printed as the value 292278994 exceeds the maximum print width of 4"
}
}
}
]
},
"status":500
}
If I specify size: 1 or size: 3 there is no error
Pinging @elastic/es-search (Team:Search)
@einfoman thanks for the detailed reproduction, I can see the same error on 7.10. Interestingly the date format seems to play a role here. Using strict_date_optional_time (the default) doesn't show this error.
Additional finding: this only happens for "missing": "_last" (which seems to be the default when left out). Using explicit "missing" : "_first" sorts the doc containing null correctly in the first position.
The date formatter printer that comes with "basic_date_time_no_millis" isn't able to format Long.MAX_VALUE which we use implicitely for sort order "_last" here.
I opened https://github.com/elastic/elasticsearch/pull/65945 with a potential fix.
@einfoman thanks for the detailed reproduction, it helped a great deal getting close to the cause of this fast. I merged a fix that should be in 7.11.0 once it is out. As a fix in the meantime, I think you should be able to set the missing value in your sort to a very large value that is still accepted by your date format (I think in this case something with a year of "9999", maybe with additional hourse etc...) should work.
@cbuescher Thank you!