Merging two nested fields with update_by_query

Hello elastic community,

I'm trying to merge two nested fields from two different documents. The nested fields have objects inside of them.

I tried to load the nested array from the first document and add it to the nested field in the second document but have no luck. The query seems to work but nothing change in the document.

client.update_by_query index: 'event_lists', conflicts: "proceed",
                           body: {
                             "script": {"source": "
                             ArrayList events = params.events;
                             if (ctx._id == params.to_model_id) { 
                               for(event in events) {	
                         	  ctx._source.events.add(event);
                             }}",
                            "lang": "painless",
                            "params": {
                              to_model_id => to_model_id,
                              events => events
                            }
                         }
                       }

Here is the response I get

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

Hey,

I am not sure I get understand request, maybe you can add a little more details. My biggest issue is, that you cannot access the values of another document in an update by query.

Can you provide a complete, but minimal example someone can copy & paste in Kibana Dev Tools including index/document creation and that update by query call?

Thank you!

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.