【问题标题】:Elasticsearch bulk set _idElasticsearch 批量设置_id
【发布时间】:2020-08-11 01:01:01
【问题描述】:

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

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

使用客户端.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

我应该使用其他方法吗?

谢谢。

【问题讨论】:

    标签: javascript node.js elasticsearch


    【解决方案1】:

    它需要在命令部分,但您还需要将其从doc的源文档中删除:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-03-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-10
      • 2020-08-12
      • 2014-11-27
      • 1970-01-01
      相关资源
      最近更新 更多