首页 > 解决方案 > 如何在 elasticsearch python 客户端的 es.index 中设置映射?

问题描述

我有 json 格式的 twitter 数据,我必须使用弹性搜索对其进行索引。我还必须为数据指定映射。

es = Elasticsearch([{'host': 'localhost', 'port': 9200}])
mapping='''{"mappings": {"_doc": {"properties":.......'''
for i,record in enumerate(data):
    es.index(index='index', doc_type='tweet', id=i, body=record)

我应该在哪里指定我的映射?

我读到我可以指定映射es.indices.create

es.indices.create(.......,body=mapping)

但是然后我如何输入我的记录数据?es.indices.create、es.index 和 es.create 有什么区别?

标签: python-3.xelasticsearch

解决方案


推荐阅读