failed to parse field [review_start_datetime] of type [date] in document with id 'DEMO_54ddab6'

Viewed 3584

Index Mapping

"review_start_datetime" : {
   "type" : "date"
},
"review_start_time" : {
   "type" : "date"
}

Class

from elasticsearch_dsl import Document, Date

class DocumentX(Document):
    review_start_datetime = Date(format='yyyy-MM-dd HH:mm:ss',
                            default_timezone="UTC")

Creating Data

doc = DocumentX.get('DEMO_54ddab6')
doc.review_start_time = datetime.datetime.now()
doc.review_start_datetime = datetime.datetime.now()
doc.save()

While executing save method it gives below error only for review_start_datetime field not for review_start_time.

elasticsearch.exceptions.RequestError: RequestError(400, 'mapper_parsing_exception', "failed to parse field [review_start_datetime] of type [date] in document with id 'DEMO_54ddab6'")

2 Answers

By Adding DateTime format in index mapping it will resolve.

"review_start_datetime" : {
    "type" : "date",
    "format" : "yyyy-MM-dd HH:mm:ss"
},

I encountered the same error in various tools, e.g., Apache NiFi, and Logstash. The problem in my case is that I want to put MongoDB documents in the Elasticsearch index, where these documents already include the _id field, and when I want to make that Elasticsearch database, the new field _id will be made that can not exist with the earlier one. So, this results in the error. The solution may be to remove/change _id field in the documents before putting them into Elastic.

Related