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

[DOC] date field type supports negative values despite what the documentation claims #9421

Open
1 of 4 tasks
gweyeratlassian opened this issue Mar 13, 2025 · 1 comment
Open
1 of 4 tasks

Comments

@gweyeratlassian
Copy link

What do you want to do?

  • Request a change to existing documentation
  • Add new documentation
  • Report a technical problem with the documentation
  • Other

Tell us about your request. Provide a summary of the request.

The Date field type documentation states that "the value must be non-negative":

Image

This is incorrect. The only negative value that is not supported is -9223372036854775808 (Long.MIN_VALUE in Java).

Version: List the OpenSearch version to which this issue applies, e.g. 2.14, 2.12--2.14, or all.

all

What other resources are available? Provide links to related issues, POCs, steps for testing, etc.

First I created an index with a date mapping:

curl -X PUT 'http://localhost:9200/date' \
-H 'Content-Type: application/json' \
-d '{
  "settings": {
    "index": {
      "number_of_shards": 1,
      "number_of_replicas": 1
    }
  },
  "mappings": {
    "dynamic": "strict",
    "properties": {
      "dateField": {
        "type": "date",
        "doc_values": true,
        "store": true
      }
    }
  }
}'

I then successfully indexed a document with a negative value:

curl -X PUT 'http://localhost:9200/date/_doc/date-1' \
-H 'Content-Type: application/json' \
-d '{
  "dateField": -1,
}'

I was able to search for the document using a range query:

curl 'http://localhost:9200/date/_search' \
-H 'Content-Type: application/json' \
-d '{
  "query": {
    "range": {
      "dateField": {
        "gte": -1
      }
    }
  }
}'

I was also able to use a date histogram with a time zone:

curl 'http://localhost:9200/date/_search' \
-H 'Content-Type: application/json' \
-d '{
  "query": {
    "match_all": {}
  },
  "size": 0,
  "aggs": {
    "will_it_work_for_negative?": {
      "date_histogram": {
        "field": "dateField",
        "calendar_interval": "day",
        "time_zone": "America/New_York"
      }
    }
  }
}'
@andrross
Copy link
Member

Catch All Triage - 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants