Skip to content

Ascending sort with missing _first fails on datefields with missing values #81960

@stu-elastic

Description

@stu-elastic

Elasticsearch version (bin/elasticsearch --version): v8.1.0, v7.16.2 and at least v7.15.1

Description of the problem including expected versus actual behavior:

Indexing a document with a missing date time value, then ascending sorting it with "missing": "_first" results in Field Year cannot be printed as the value -292275055 exceeds the maximum print width of 4 if it would be the only document returned, ie size: 1.

The formatter is trying to format the sentinel value of -9223372036854775808.

Steps to reproduce:

PUT test
{
  "mappings" : {
    "properties" : {
      "field1" : {
        "type" : "integer"
      },
      "dt" : {
        "type" : "date",
        "format" : "strict_date_time||strict_date_time_no_millis"
      }
    }
  }
}

POST _bulk
{"index":{"_index":"test","_id":"1"}}
{"field1": 1243, "dt": "2021-12-20T23:14:20+00:00"}
{"index":{"_index":"test","_id":"2"}}
{"field2": 4567}

GET test/_search
{
  "size": 1,
  "query": {
    "match_all": {}
  },
  "sort": [
    {
      "dt": {
        "missing": "_first",
        "order": "asc"
      }
    }
  ]
}

This is #73763 with targetNumericType == NumericType.DATE

Using "missing": 0 works around the issue.

Metadata

Metadata

Assignees

Labels

:Search Relevance/SearchCatch all for Search Relevance>bugTeam:Search RelevanceMeta label for the Search Relevance team in Elasticsearchpriority:normalA label for assessing bug priority to be used by ES engineers

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions