首页 > 解决方案 > 如何使用 Python3 解决 Elasticsearch 中的 BUG INTEGER 映射问题?

问题描述

我必须索引一些数据,其中一行具有值:

'c_22': {
            'raw': '53095200303310000118800091005',
            'integer': 53095200303309998490927497216
        },

这是将在 Elasticsearch 中作为文档索引的键值对之一。虽然,Python3 能够将其作为整数,但在 Elasticsearch 中对其进行索引会引发错误:

'error': {
        'caused_by': {
            'type': 'illegal_state_exception',
            'reason': 'No matching token for number_type [BIG_INTEGER]'
        },
        'type': 'mapper_parsing_exception',
        'reason': 'failed to parse'
    },
    '_index': '8ca178b8cc4dd678147409af92029685',
    '_id': 'b4505cd90c5e6c47c38889c5722ff495',
    'status': 400
}

注意:上面发布的值是我对这个错误的根本原因的估计。调试器打印出来的完整行在这里

标签: python-3.xelasticsearch

解决方案


我通过以下方式做对了:

if _datatype == "number":
   column_parsed_value *= 1.0 #in order to avoid biginteger issue in es.

这是解决 bigint 问题的标准方法;Python 可以,但 ES 不行。


推荐阅读