2

假设我有 1000 个用户,每个用户有 50 个文档(每个文档嵌入具有名称和电子邮件的用户对象),我需要更新一组用户的名称和电子邮件。

我想使用 Bulk Api,但似乎 bulk API 只支持“_id”作为参数。我想改为查询

例如:我想做,

POST _bulk
{ "update" : {"query" : {"terms": {"userId": "25"}}, "_type" : "comments", "_index" : "comments"} }
{ "doc" : {"user.name" : "new name"} }

代替

POST _bulk
{ "update" : {"_id" : "1", "_type" : "comments", "_index" : "comments"} }
{ "doc" : {"user.name" : "new name"} }
4

1 回答 1

0

为此,您可以使用查询 API 更新:

POST comments/_update_by_query
{
  "script": {
    "inline": "ctx._source.user.name = newName",
    "lang": "painless",
    "params": {
      "newName": "new name"
    }
  },
  "query": {
    "term": {
      "userId": "25"
    }
  }
}
于 2017-06-02T11:49:12.347 回答