Skip to content

Sorting descending on datefield with nanosecond-precision fails for missing values #73763

@EmilBode

Description

@EmilBode

Elasticsearch version: 7.13.1 (newest)

Plugins installed: None

JVM version: ES builtin,
openjdk 16 2021-03-16
OpenJDK Runtime Environment AdoptOpenJDK (build 16+36)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 16+36, mixed mode, sharing)

OS version: Windows 10, 64bit, version 2004, build 19041.985

Steps to reproduce:

POST _bulk
{"index":{"_index":"test","_id":"1"}}
{"field1":"value1", "timestamp": "2021-06-04T13:50:00.000000001"}
{"index":{"_index":"test","_id":"2"}}
{"field1":"value2"}

And the query

GET test/_search
{
  "sort": {
    "timestamp": {
      "order": "desc",
      "format": "strict_date_optional_time_nanos",
      "numeric_type": "date_nanos"
    }
  }
}

Expected behaviour
I'd expect both docs to be returned without errors (first doc1, then doc2 with a missing timestamp)

Actual behaviour

{
  "error" : {
    "root_cause" : [ ],
    "type" : "search_phase_execution_exception",
    "reason" : "",
    "phase" : "fetch",
    "grouped" : true,
    "failed_shards" : [ ],
    "caused_by" : {
      "type" : "illegal_argument_exception",
      "reason" : "nanoseconds [-9223372036854775808] are before the epoch in 1970 and cannot be processed in nanosecond resolution"
    }
  },
  "status" : 400
}

Observations

My guess would be that missing values are filled in with a value "before any possible value" (to be first for ascending order, or last in descending order), but that this subsequently fails when showing as a formatted date.

Metadata

Metadata

Assignees

Labels

:Search/SearchSearch-related issues that do not fall into other categories>bugTeam:SearchMeta label for search team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions