[英]Elasticsearch bulk set _id
When I'm adding docs to elasticsearch with _id set I get:当我将文档添加到 elasticsearch 并设置 _id 时,我得到:
Field [_id] is a metadata field and cannot be added inside a document. Use the index API request parameters.
Using client.bulk使用 client.bulk
const body = dataset.flatMap(doc => [{ index: { _index: 'myindex' } }, doc])
const { body: bulkResponse } = await client.bulk({ refresh: true, body })
I don't see a place to put the _id in the parameters.我没有看到将 _id 放入参数的地方。
https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference.html https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference.html
Am I supposed to use a different method?我应该使用不同的方法吗?
Thanks.谢谢。
It needs to be inside the command part, but you also need to remove it from the source document in doc
:它需要在命令部分内,但您还需要将其从doc
的源文档中删除:
here
|
v
const body = dataset.flatMap(doc => [{ index: { _index: 'myindex', _id: doc._id } }, doc])
const { body: bulkResponse } = await client.bulk({ refresh: true, body })
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.