I am having a problem to parse some dates in elasticsearch. I have posted about the problem in stackoverflow. Please help me on this as i also could have some yyyy-mm-dd format dates along with epoch.
Thank you,
I am having a problem to parse some dates in elasticsearch. I have posted about the problem in stackoverflow. Please help me on this as i also could have some yyyy-mm-dd format dates along with epoch.
Thank you,
Hey
It'd be better to post here the question instead of a link to another website.
That way the question and the answers will be searchable.
Thanks
Hi dadoonet,
Thank you for notifying me. I will explain the problem here.
My es version is 7.5.1.
I created an index 'abc':
curl -XPUT localhost:9200/abc
Now my mapping is:
curl -XPUT "localhost:9200/abc/_mapping" -H 'Content-Type:application/json' -d'
{
"properties": {
"memberDOB": {
"type": "date"
}
}
}
'
And,
As per this link,
it says:
Date formats can be customised, but if no format is specified then it uses the default: "strict_date_optional_time||epoch_millis"
So I didn't mention any format explicitly.
for inserting the date1: '1969-11-19'
curl -XPOST "localhost:9200/abc/_doc" -H 'Content-Type: application/json' -d'
{
"memberDOB" : -3715200000
}'
It gives me error:
{"error":{"root_cause":[{"type":"mapper_parsing_exception","reason":"failed to parse field [memberDOB] of type [date] in document with id 'Z7or5m8BpAMrohtXunLI'.
Preview of field's value: '-3715200000'"}],"type":"mapper_parsing_exception","reason":"failed to parse field [memberDOB] of type [date] in document with id
'Z7or5m8BpAMrohtXunLI'. Preview of field's value: '-3715200000'","caused_by":{"type":"date_time_exception","reason":"Invalid value for Year (valid values -999999999 - 999999999): -3715200000"}},"status":400}
From the mentioned exception, it seems that the epoch date is being treated as yyyy-mm-dd format.
for date2: '1965-10-11'
curl -XPOST "localhost:9200/abc/_doc" -H 'Content-Type: application/json' -d'
{
"memberDOB" : -133335000000
}'
It works fine.
Also for date3 in yyyy-mm-dd format:
curl -XPOST "localhost:9200/abc/_doc" -H 'Content-Type: application/json' -d'
{
"memberDOB" : "2001-11-12"
}'
It works fine.
I also updated the format as "format":"strict_date_optional_time||epoch_millis" in new index and tried to write, but still same error occurs for date1(-3715200000).
But when I update the format as "format":"epoch_millis", it works.
Could you please explain why this is happening or what am I missing here (for default format)?
Thank you,
Please format your code, logs or configuration files using </>
icon as explained in this guide and not the citation button. It will make your post more readable.
Or use markdown style like:
```
CODE
```
This is the icon to use if you are not using markdown format:
There's a live preview panel for exactly this reasons.
Lots of people read these forums, and many of them will simply skip over a post that is difficult to read, because it's just too large an investment of their time to try and follow a wall of badly formatted text.
If your goal is to get an answer to your questions, it's in your interest to make it as easy to read and understand as possible.
Please update your post.
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
© 2020. All Rights Reserved - Elasticsearch
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant logo are trademarks of the Apache Software Foundation in the United States and/or other countries.