使用 Elasticsearch 的 Update API 可以根据两个字段修改文档数据。以下是一个示例请求体:

POST /index/_update/document_id
{
  "script": {
    "source": "ctx._source.field1 = params.newValue1; ctx._source.field2 = params.newValue2",
    "params": {
      "newValue1": 'new value 1',
      "newValue2": 'new value 2'
    }
  }
}

其中,'index' 是要更新的索引名称,'document_id' 是要更新的文档的 ID。'field1' 和 'field2' 是要修改的字段名称,'newValue1' 和 'newValue2' 是要设置的新值。

注意:

  • 通过 Update API 只能修改已存在的文档。如果要修改的文档不存在,则会报错。
  • 如果需要在文档不存在时创建新文档,请使用 Upsert API。

原文地址: https://www.cveoy.top/t/topic/pjHZ 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录