弹性搜索在单个查询请求中更新多个字段

Elastic search update multiple fields in single query request

在ES 5.x版本上工作,需要使用script.Also共享更新多个字段更新,有更好的解决方案。

POST ../100/_update
    {
    "script" : {
        "inline": "ctx._source.student.hobbies.add(params.tag)",
        "lang": "painless",
        "params" : {
            "tag" : "cricket"
        }
    }
}

也是我需要更新的同一个学生phone不。现在我打电话给 2 api 更新爱好和 phone 号码。寻找更好的解决方案来更新单个查询

只需在两个语句之间添加一个分号,如下所示:

{
  "script": {
    "inline": "ctx._source.student.hobbies.add(params.hobby); ctx._source.student.phone.add(params.phone)",
    "lang": "painless",
    "params": {
      "hobby": "cricket",
      "phone" : "122-33-4567"
    }
  }
}

如果要将多个值添加到数组中,可以这样做

{
  "script": {
    "inline": "ctx._source.student.hobbies.addAll(params.hobbies); ctx._source.student.phone.add(params.phone)",
    "lang": "painless",
    "params": {
      "hobbies": ["football", "cricket"],
      "phone" : "122-33-4567"
    }
  }
}