簡體   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