Elasticsearch Scripting: updating array value

前端 未结 1 1035
逝去的感伤
逝去的感伤 2021-02-06 09:25

This is my document

{
    \"name\": \"andrew\",
    \"b\": [{\"x\":\"c1\", \"y\": 0}, {\"x\":\"c2\", \"y\": 0}]
}

I want to find element in the

相关标签:
1条回答
  • 2021-02-06 09:42

    Use this instead:

    {
      "script": "for (int i=0;i<ctx._source.b.size();i++) { item=ctx._source.b[i]; if (item['x'] == x_id) { ctx._source.b[i] = newobj} };",
      "params": {
        "x_id": "c1",
        "newobj": {
          "x": "c1",
          "y": 4222
        }
      },
      "lang": "groovy"
    }
    
    0 讨论(0)
提交回复
热议问题