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

Inserting epoch date throws illegal_argument_exception #99486

Closed
enricrp8 opened this issue Sep 12, 2023 · 4 comments
Closed

Inserting epoch date throws illegal_argument_exception #99486

enricrp8 opened this issue Sep 12, 2023 · 4 comments
Labels
>bug :Search Foundations/Mapping Index mappings, including merging and defining field types Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch

Comments

@enricrp8
Copy link

Elasticsearch Version

7.17.5

Installed Plugins

No response

Java Version

openjdk version "18.0.1.1" 2022-04-22

OS Version

Linux 49997dcae70d 6.2.0-32-generic #32~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Fri Aug 18 10:40:13 UTC 2 x86_64 x86_64 x86_64 GNU/Linux

Problem Description

I cannot understand why there are some epochs that fail to insert into elastic. However, if I execute `new Node(<epoch_milis_that_fails_in_es>) It returns a valid date. I first thought that it was because of the milliseconds becaus, for some reason, the date -5101599088102 fails to insert, but neither -5101599088000 or -5101599089000 fails. However, I tried other dates with milliseconds and they are accepted.
Anyone knows the reason why or if it is a bug?

Steps to Reproduce

create an index, for example an index with name 'test__v1' with the following body

curl --request PUT \
  --url http://localhost:9200/test__v1 \
  --header 'Content-Type: application/json' \
  --data '{
	"settings": {},
	"mappings": {
		"dynamic": "strict",
		"properties": {
			"insertedDate": {
				"type": "date",
				"format": "epoch_millis"
			}
		}
	}
}'

Then try inserting the date -5101599088102:

curl --request PUT \
  --url http://localhost:9200/test/_create/testing-id \
  --header 'Content-Type: application/json' \
  --data '{
	"insertedDate": -5101599088102
}'

This will throw the following error:

{
	"error": {
		"root_cause": [
			{
				"type": "mapper_parsing_exception",
				"reason": "failed to parse field [insertedDate] of type [date] in document with id 'testing-id'. Preview of field's value: '-5101599088102'"
			}
		],
		"type": "mapper_parsing_exception",
		"reason": "failed to parse field [insertedDate] of type [date] in document with id 'testing-id'. Preview of field's value: '-5101599088102'",
		"caused_by": {
			"type": "illegal_argument_exception",
			"reason": "failed to parse date field [-5101599088102] with format [epoch_millis]",
			"caused_by": {
				"type": "date_time_parse_exception",
				"reason": "Failed to parse with all enclosed parsers"
			}
		}
	},
	"status": 400
}

Now try inserting the date -5101599088000:

{
	"_index": "test__v1",
	"_type": "_doc",
	"_id": "testing-id",
	"_version": 1,
	"result": "created",
	"_shards": {
		"total": 2,
		"successful": 1,
		"failed": 0
	},
	"_seq_no": 0,
	"_primary_term": 1
}

Finally if I insert a date with milliseconds

curl --request PUT \
  --url http://localhost:9200/test/_create/testing-id2 \
  --header 'Content-Type: application/json' \
  --data '{
	"insertedDate": 1694529437654
}'

It returns okay:

{
	"_index": "test__v1",
	"_type": "_doc",
	"_id": "testing-id2",
	"_version": 1,
	"result": "created",
	"_shards": {
		"total": 2,
		"successful": 1,
		"failed": 0
	},
	"_seq_no": 2,
	"_primary_term": 1
}

Logs (if relevant)

No response

@enricrp8 enricrp8 added >bug needs:triage Requires assignment of a team area label labels Sep 12, 2023
@kingherc kingherc added the :Search Foundations/Mapping Index mappings, including merging and defining field types label Sep 12, 2023
@elasticsearchmachine elasticsearchmachine added Team:Search Meta label for search team and removed needs:triage Requires assignment of a team area label labels Sep 12, 2023
@elasticsearchmachine
Copy link
Collaborator

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

@enricrp8
Copy link
Author

any news about this?

@cbuescher
Copy link
Member

This has been discussed in #72123, take a look at #72123 (comment).
However correct support seems to have been added back in #80208 which should be available from version 8.2 on. I just tested your case on a current 8.10 version and it seems to work okay.
I will close this since we won't backport that change to the 7.17 line of maintenance releases.

@enricrp8
Copy link
Author

This has been discussed in #72123, take a look at #72123 (comment). However correct support seems to have been added back in #80208 which should be available from version 8.2 on. I just tested your case on a current 8.10 version and it seems to work okay. I will close this since we won't backport that change to the 7.17 line of maintenance releases.

Perfect, thank you

@javanna javanna added Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch and removed Team:Search Meta label for search team labels Jul 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug :Search Foundations/Mapping Index mappings, including merging and defining field types Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch
Projects
None yet
Development

No branches or pull requests

5 participants