【发布时间】:2023-01-09 00:52:05
【问题描述】:
我正在尝试将小文档从 MongoDB 导入 ElasticSearch 但出现错误
{
"index": {
"_index": "impact-fulltext",
"_id": "t2oLkoUBwNXsTufYzszL",
"status": 400,
"error": {
"type": "mapper_parsing_exception",
"reason": "failed to parse field [_id] of type [_id] in document with id \u0027t2oLkoUBwNXsTufYzszL\u0027. Preview of field\u0027s value: \u0027605315a3b4f719d00f69f2d3\u0027",
"caused_by": {
"type": "mapper_parsing_exception",
"reason": "Field [_id] is a metadata field and cannot be added inside a document. Use the index API request parameters."
}
}
}
}
我一无所知,因为我也定义了 _id 但仍然出现错误。
db.collection("article_beta")
.find()
.limit(100)
.toArray((err, docs) => {
if (err) throw err;
esClient.bulk(
{
body: docs.flatMap((doc) => [
{
index: {
_index: "impact-fulltext",
_id: doc._id.$oid,
},
},
doc,
]),
},
(err, resp) => {
if (err) throw err;
console.log(resp);
client.close();
}
);
});
【问题讨论】:
标签: node.js mongodb elasticsearch