由于mapper_parsing_exception,无法在 elasticsearch 中插入日期



我正在插入数据到elasticsearch:

client.index(index: "dev_index", id: 123, body: {"test_date": "2019-01-01 00:00:00"}
{
"mappings":{
"dynamic":false,
"properties":{
"test_date":{
"type":"date",
"format":"yyyy-mm-dd hh:mm:ss"
}
}
}
}

然而,当我尝试插入数据时,我看到以下错误:

{
"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

我在这里做错了什么?索引14似乎指的是会议记录,但我不确定这里的问题是什么。

看起来您在映射中错误地提到了日期格式。应该是"yyyy-MM-dd HH:mm:ss"(大写M表示月)

在您的地图中,您提到了月和分钟的"mm"。修改映射,如下所示:

{"mappings" {"dynamic"假的,"properties" {"test_date" {"type"date"format"yyyy-MM-dd hh: mm: ss"}}}}

最新更新