Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Date formatting error when doing descending sort on empty epoch_millis date field #103489

Open
Tracked by #103753 ...
vishalgoel2 opened this issue Dec 15, 2023 · 2 comments
Labels
>bug :Search/Search Search-related issues that do not fall into other categories Team:Search Meta label for search team

Comments

@vishalgoel2
Copy link

Elasticsearch Version

8.11.3

Installed Plugins

No response

Java Version

bundled

OS Version

Linux 69d007f8c352 6.4.16-linuxkit #1 SMP PREEMPT Thu Nov 16 10:49:20 UTC 2023 aarch64 aarch64 aarch64 GNU/Linux

Problem Description

Summary

Encountering a date formatting issue in Elasticsearch 8.x.x when performing a search with sorting the documents in descending order based on the date type field with the epoch_millis format

Expected Result

The search results should be returned without errors, and the documents should be sorted by the date field in descending order.

Actual Result

Encountering a date_time_exception with the reason Field EpochMillis cannot be printed as the value -9223372036854775808 cannot be negative according to the SignStyle

Additional Information

  • This issue is reproducible consistently.
  • The date mapping is configured with the epoch_millis format.
  • There should be at least one document with an empty date field to trigger the date_time_exception.
  • The error occurs when attempting to perform a search with sorting by date in descending order.
  • This issue is not present in Elasticsearch version 7.x.x, and sorting by date in descending order works as expected in the earlier version.

Steps to Reproduce

  1. Create an index with a date field mapping using the epoch_millis format

    curl -X PUT "http://localhost:64780/event" -H 'Content-Type: application/json' -d '
    {
      "mappings": {
        "properties": {
          "id": {
            "type": "keyword"
          },
          "date": {
            "type": "date",
            "format": "epoch_millis"
          }
        }
      }
    }'
  2. Populate the index with sample data using the Bulk API

    curl -X POST "http://localhost:64780/event/_bulk" -H "Content-Type: application/x-ndjson" --data-binary @- <<EOF
    {"index":{"_id":"1"}}
    {"id":"1","date":1702578895}
    {"index":{"_id":"2"}}
    {"id":"2","date":1702578895}
    {"index":{"_id":"3"}}
    {"id":"3","date":1702578895}
    {"index":{"_id":"4"}}
    {"id":"4","date":1702578895}
    {"index":{"_id":"5"}}
    {"id":"5","date":1702578895}
    {"index":{"_id":"6"}}
    {"id":"6","date":1702578895}
    {"index":{"_id":"7"}}
    {"id":"7","date":1702578895}
    {"index":{"_id":"8"}}
    {"id":"8","date":1702578895}
    {"index":{"_id":"9"}}
    {"id":"9","date":1702578895}
    {"index":{"_id":"10"}}
    {"id":"10"}
    EOF
  3. Attempt to perform a search with sorting by date in descending order

    curl -X GET "http://localhost:64780/event/_search?sort=date:desc" -H 'Content-Type: application/json'

    Response

    {"error":{"root_cause":[{"type":"date_time_exception","reason":"Field EpochMillis cannot be printed as the value -9223372036854775808 cannot be negative according to the SignStyle"}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"event","node":"3PjSjabrRgqTQrWNZG4GyQ","reason":{"type":"date_time_exception","reason":"Field EpochMillis cannot be printed as the value -9223372036854775808 cannot be negative according to the SignStyle"}}],"caused_by":{"type":"date_time_exception","reason":"Field EpochMillis cannot be printed as the value -9223372036854775808 cannot be negative according to the SignStyle","caused_by":{"type":"date_time_exception","reason":"Field EpochMillis cannot be printed as the value -9223372036854775808 cannot be negative according to the SignStyle"}}},"status":500}

### Logs (if relevant)

_No response_
@vishalgoel2 vishalgoel2 added >bug needs:triage Requires assignment of a team area label labels Dec 15, 2023
@dnhatn dnhatn added the :Search/Search Search-related issues that do not fall into other categories label Dec 16, 2023
@elasticsearchmachine elasticsearchmachine added Team:Search Meta label for search team and removed needs:triage Requires assignment of a team area label labels Dec 16, 2023
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-search (Team:Search)

@ghostspiders
Copy link

This is a bug, use the format "strict_date_optional_time||epoch_millis" to avoid this error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug :Search/Search Search-related issues that do not fall into other categories Team:Search Meta label for search team
Projects
None yet
Development

No branches or pull requests

4 participants