Elasticsearch js 如何向上插入文档

Zhe*_*Liu 7 elasticsearch

我想为一个文件做一个 upsert。目前是否可以通过 nodejs elasticsearch API 做到这一点?

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

我查看了 API,我只能看到更新的 upsert 选项。

这是否意味着目前我没有任何方法可以更新文档?

谢谢

Tib*_*ksa 11

调用方法插入文档时,将doc_as_upsert参数设置为。trueupdate

const response = await client.update({
  index: 'myindex',
  type: 'mytype',
  id: '1',
  body: {
    doc: {
      title: 'Updated'
    },
    doc_as_upsert: true
  }
});
Run Code Online (Sandbox Code Playgroud)