如何修复 ElasticSearch "Types cannot be provided in put mapping requests, unless the include_type_name parameter is set to true"

问题:

你想在 ElasticSearch 中创建映射,但你看到类似这样的错误消息

es_mapping_error_output.txt
elasticsearch.exceptions.RequestError: RequestError(400, 'illegal_argument_exception', 'Types cannot be provided in put mapping requests, unless the include_type_name parameter is set to true.')

解决方案

如错误消息中已建议的,将 include_type_name 参数设置为 True

使用 Python API,这就像在 put_mapping(...) 调用中添加 include_type_name=True 一样简单:

es_put_mapping_fix.py
es.indices.put_mapping(index='my_index', body=my_mapping, doc_type='_doc', include_type_name=True)

如果你现在看到类似这样的错误

es_put_mapping_typeerror.txt
TypeError: put_mapping() got an unexpected keyword argument 'include_type_name'

你需要升级你的 elasticsearch python 库,例如使用

upgrade_elasticsearch_pip.sh
pip install -U elasticsearch

Check out similar posts by category: Databases, ElasticSearch, Python