hadoop - Elasticsearch 在单个查询请求中更新多个字段

标签 hadoop elasticsearch elasticsearch-plugin

在 ES 5.x 版本上工作,需要使用脚本更新多个字段更新。也分享一下,有更好的解决方案。

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

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

最佳答案

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

{
  "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"
    }
  }
}

关于hadoop - Elasticsearch 在单个查询请求中更新多个字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48947107/

相关文章:

java - Java线程未在JDBC程序中进行

hadoop - 如何构建大小不适合 RAM 的布隆过滤器?

Elasticsearch - 如何存储数据,嵌套或数组?

python - python elasticsarch集成

java - 将 Elasticsearch 的 DeleteByQueryPlugin 从 2.4 迁移到 5.2.2

Hadoop Kerberos : hdfs command 'Failed to find any Kerberos tgt' even though I had got one ticket using kinit

hadoop - 如何高效查找top-k元素?

security - 通过浏览器保护 Elasticsearch 访问

elasticsearch - CouchBase复制错误到 Elasticsearch

java - 如何在 Elasticsearch 中索引 pdf 文档内容?