0

发布汽车/_update_by_query

{
  "query": {
    "match_all": {}
  },
  "script": {
    "inline": "ctx._source.addresses = [{country:'Country', countryCode : 'cr'}]",
    "lang": "painless"
  }
}

脚本成功运行,没有出现错误,输出如下,但没有更新。

{
  "took" : 18092,
  "timed_out" : false,
  "total" : 400000,
  "updated" : 400000,
  "deleted" : 0,
  "batches" : 400,
  "version_conflicts" : 0,
  "noops" : 0,
  "retries" : {
    "bulk" : 0,
    "search" : 0
  },
  "throttled_millis" : 0,
  "requests_per_second" : -1.0,
  "throttled_until_millis" : 0,
  "failures" : [ ]
}

谢谢

4

1 回答 1

3

您的脚本需要看起来像这样:

"inline": "ctx._source.addresses = [['country':'Country', 'countryCode' : 'cr']]",

请注意,Painless 不直接处理 JSON,您需要通过ArraysMaps来代替。作为证明,在上面运行您的查询,我收到以下错误:

"script" : "ctx._source.addresses = [{country:'Country', countryCode : 'cr'}]",
"lang" : "painless",
"position" : {
  "offset" : 25,
  "start" : 0,
  "end" : 50
},
"caused_by" : {
  "type" : "illegal_argument_exception",
  "reason" : "invalid sequence of tokens near ['{'].",
  "caused_by" : {
    "type" : "no_viable_alt_exception",
    "reason" : null
  }
}
于 2021-04-21T14:43:30.357 回答