I am inserting data to elasticsearch:
client.index(index: "dev_index", id: 123, body: {"test_date": "2019-01-01 00:00:00"}
using the mappings in the format below:
{
"mappings":{
"dynamic":false,
"properties":{
"test_date":{
"type":"date",
"format":"yyyy-mm-dd hh:mm:ss"
}
}
}
}
However I am seeing the below error when I try to insert data:
{
"error":{
"root_cause":[
{
"type":"mapper_parsing_exception",
"reason":"failed to parse field [test_date] of type [date] in document with id '1234'. Preview of field's value: '2019-01-01 00:00:00'"
}
],
"type":"mapper_parsing_exception",
"reason":"failed to parse field [test_date] of type [date] in document with id '1234'. Preview of field's value: '2019-01-01 00:00:00'",
"caused_by":{
"type":"illegal_argument_exception",
"reason":"failed to parse date field [2019-01-01 00:00:00] with format [yyyy-mm-dd hh:mm:ss]",
"caused_by":{
"type":"date_time_parse_exception",
"reason":"Text '2019-01-01 00:00:00' could not be parsed at index 14"
}
}
},
"status":400
What am I doing wrong here? Index 14 seems to be referring to the minutes but I'm not sure what the issue is here.
CodePudding user response:
You can solve this issue by reformatting the date format in the mapping file
CodePudding user response:
Looks like you have mentioned the date format incorrectly in your mapping. It should be "yyyy-MM-dd HH:mm:ss" (uppercase M for Months)
In your Mapping you have mentioned 'mm' for Months as well as minutes. Correct your mapping as below:
{ "mappings":{ "dynamic":false, "properties":{ "test_date":{ "type":"date", "format":"yyyy-MM-dd hh:mm:ss" } } } }