2

In Elasticsearch, one of my field is a date which I define the mapping with custom date format matching my date.

However, some cases the value of my date field is just an empty string "LastUpdateDate": "" and causes an exception. How can I handle the empty string in the mapping for the date field?

Unexpected error:  (<class 'elasticsearch.helpers.BulkIndexError'>, BulkIndexError(u'1 document(s) failed to index.', [{u'create': 
{u'status': 400, u'_type': u'songs', u'_id': u'AVNtiXgTC4kaHLfuKAJA', u'error': {u'caused_by': {u'reason': u'Invalid format: ""', 
u'type': u'illegal_argument_exception'}, u'reason': u'failed to parse [LastUpdateDate]', u'type': u'mapper_parsing_exception'}, 
u'_index': u'album-032016'}}]), <traceback object at 0x7fba4395c1b8>)
Philip K. Adetiloye
  • 3,102
  • 4
  • 37
  • 63

1 Answers1

6

You should use null rather than "" in the LastUpdateDate date field.

The other option is to modify the index level settings : index.mapping.ignore_malformed:true

Trying to index the wrong datatype into a field throws an exception by default, and rejects the whole document. The ignore_malformed parameter, if set to true, allows the exception to be ignored. The malformed field is not indexed, but other fields in the document are processed normally.

https://www.elastic.co/guide/en/elasticsearch/reference/current/ignore-malformed.html

Rahul
  • 15,979
  • 4
  • 42
  • 63