当我将从 MongoDB java 驱动程序函数返回的 org.bson.Document 传递给 elasticsearchMongoDatabase.getCollection().find()
索引时,我得到以下异常。
MapperParsingException[Field [_id] is a metadata field and cannot be added inside a document. Use the index API request parameters.]
这是代码,
MongoCursor<Document> cursor = mongoCollection.find().iterator();
Document doc = cursor.next();
IndexRequest indexRequest = new IndexRequest(indexName, indexType);
indexRequest.source(doc.toJson());
BulkRequestBuilder bulkRequest = client.prepareBulk();
bulkRequest.add(indexRequest);
bulkRequest.execute().actionGet();
但是在传递从返回的 pymongo 文档时没有收到这样的错误MongoClient().mydb.collection_name.find()
这些 API 有什么区别?与 pymongo 的 find() API 等效的 java 是什么?