Har*_*rry 2 javascript node.js elasticsearch
当我使用 _id 设置将文档添加到 elasticsearch 时,我得到:
Field [_id] is a metadata field and cannot be added inside a document. Use the index API request parameters.
Run Code Online (Sandbox Code Playgroud)
使用 client.bulk
const body = dataset.flatMap(doc => [{ index: { _index: 'myindex' } }, doc])
const { body: bulkResponse } = await client.bulk({ refresh: true, body })
Run Code Online (Sandbox Code Playgroud)
我没有看到在参数中放置 _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 })
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1657 次 |
| 最近记录: |