繁体   English   中英

Elasticsearch 批量设置_id

[英]Elasticsearch bulk set _id

当我将文档添加到 elasticsearch 并设置 _id 时,我得到:

Field [_id] is a metadata field and cannot be added inside a document. Use the index API request parameters.

使用 client.bulk

  const body = dataset.flatMap(doc => [{ index: { _index: 'myindex' } }, doc])  
  const { body: bulkResponse } = await client.bulk({ refresh: true, body })

我没有看到将 _id 放入参数的地方。

https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference.html

我应该使用不同的方法吗?

谢谢。

它需要在命令部分内,但您还需要将其从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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM