我正在使用pymongo将MongoDB中的文档插入Elasticsearch,并在下面收到错误。问题看起来像'_id'。如何在将“_id”插入ElasticSearch之前将其转换为“id”?
错误:
elasticsearch.exceptions.RequestError: TransportError(400,
u'mapper_parsing_exception', u'Field [_id] is a metadata field and
cannot be added inside a document. Use the index API request
parameters.')
代码:
for doc in documents1.find():
doc_sanitized = json.loads(json_util.dumps(doc))
es.index(index='index-name', doc_type='intel', id=i, body=doc_sanitized)