Skip to content
Advertisement

How to allow ElasticSearch to accept empty date fields?

I have a Python script that I use to load some data into ElasticSearch.

One of the fields I am loading is a date field, which on some rare occasions can be empty.

In my code, if there is no date, I assign it the string "null":

details["start_time"] = project_detail.get("start_time", "null")

In this case, I am getting the following error:

***search.BadRequestError: BadRequestError(400, 'mapper_parsing_exception', "failed to parse field [start_time] of type [date] in document with id '1'. Preview of field's value: 'null'")

How can I make ES accept empty fields for this date field?

Advertisement

Answer

"null" (string) is not the same as null. ES will not be able to parse "null" as a date. You should probably just assign None instead so that the date field will just be missing.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement