Elasticsearch 映射空字符串

Elasticsearch mapping empty string

在 Elasticsearch 中,我的字段之一是日期,我使用与我的日期匹配的自定义日期格式定义映射。

但是,在某些情况下,我的日期字段的值只是一个空字符串 "LastUpdateDate": "" 并导致异常。我该如何处理空的 日期字段映射中的字符串?

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>)

您应该在 LastUpdateDate 日期字段中使用 null 而不是 ""。

另一个选项是修改索引级别设置: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