Elasticsearch partial update script: Clear array and replace with new values

后端 未结 2 649
囚心锁ツ
囚心锁ツ 2021-01-13 03:20

I have documents like:

{
  MyProp: [\"lorem\", \"ipsum\", \"dolor\"]
  ... lots of stuff here ...
}

My documents can be quite big (but thes

2条回答
  •  一向
    一向 (楼主)
    2021-01-13 04:09

    Would a _bulk update work for you?

    POST test/type1/_bulk
    {"update":{"_id":1}}
    {"script":{"inline":"ctx._source.MyProp += new_param","params":{"new_param":"bla"},"lang":"groovy"}}
    {"update":{"_id":2}}
    {"script":{"inline":"ctx._source.MyProp += new_param","params":{"new_param":"bla"},"lang":"groovy"}}
    {"update":{"_id":3}}
    {"script":{"inline":"ctx._source.MyProp += new_param","params":{"new_param":"bla"},"lang":"groovy"}}
    ....
    

    And you would also need to enable inline scripting for groovy. What the above would do is to add a bla value to the listed documents in MyProp field. Of course, depending on your requirements many other changes can be performed in that script.

提交回复
热议问题