Description
Describe the bug
When sorting by a date field, if the field is not present on a record and "missing": "_first", "order": "asc" is specified (probably also applies to opposite) in the sort array, the returned sort array returns -9223372036854775808 for the sort value. If that value is passed back into the search_after array (for the next query) as a string, an error is returned: "failed to parse date field [-9223372036854775808] with format [strict_date_optional_time||epoch_millis]"
If it is passed as a number, it works fine.
If any other valid long value is passed as a string, it works fine.
Since Long.MIN_VALUE = -Long.MAX_VALUE - 1
and Long.MIN_VALUE = -9223372036854775808
I expect that this is an unhandled edge case.
Related component
Search:Resiliency
To Reproduce
- Open the Dev Tools in the Dashboard
- Run a query which sorts on a date field and put
"-9223372036854775808"
in the search_after field - Result is error
Note: it may be required to have actual records which are missing the date field and you may need to have an ID field so the sort works correctly.
Sample query:
GET index-name/_search
{
"size": 5,
"query": {
"bool": {
"filter": [
{
"range": {
"date": {
"gte": "2024-11-26"
}
}
},
{
"range": {
"date": {
"lte": "2024-12-28"
}
}
}
]
}
},
"_source": [
"field1",
"field2"
],
"sort": [
{
"missingDatetime": {"missing": "_first", "order": "asc"}
},
{
"id": "asc"
}
],
"search_after": [
"-9223372036854775808",
"cda11fb7-d250-41e1-945c-c31f204ac51c"
]
}
Expected behavior
Query returns next set of results (no exception).
Additional Details
Plugins
None
Screenshots
Host/Environment (please complete the following information):
- Version: OpenSearch 2.15
Additional context
Full exception:
{
"error": {
"root_cause": [
{
"type": "parse_exception",
"reason": "failed to parse date field [-9223372036854775808] with format [strict_date_optional_time||epoch_millis]: [failed to parse date field [-9223372036854775808] with format [strict_date_optional_time||epoch_millis]]"
}
],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "can_match",
"grouped": true,
"failed_shards": [
{
"shard": 0,
"index": "<Index-Removed>",
"node": "<Node Removed>",
"reason": {
"type": "parse_exception",
"reason": "failed to parse date field [-9223372036854775808] with format [strict_date_optional_time||epoch_millis]: [failed to parse date field [-9223372036854775808] with format [strict_date_optional_time||epoch_millis]]",
"caused_by": {
"type": "illegal_argument_exception",
"reason": "failed to parse date field [-9223372036854775808] with format [strict_date_optional_time||epoch_millis]",
"caused_by": {
"type": "date_time_parse_exception",
"reason": "date_time_parse_exception: Failed to parse with all enclosed parsers"
}
}
}
}
]
},
"status": 400
}
Metadata
Metadata
Assignees
Labels
Type
Projects
Status