简体   繁体   English

使用 update_by_query 合并两个嵌套字段

[英]Merging two nested fields with update_by_query

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 had no luck.我试图从第一个文档加载嵌套数组并将其添加到第二个文档的嵌套字段但没有成功。 The query seems to work but nothing changes 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
                            }
                         }
                       }

This 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":[]}

The _update_by_query endpoint only operates within the context of one document. _update_by_query端点仅在一个文档的上下文中运行。 You cannot "merge" documents that way.您不能以这种方式“合并”文档。

If you want to merge documents you need to use the enrich processor and build an enrich index from some source index and then enrich the destination index from it.如果要合并文档,则需要使用enrich处理器并从某个源索引构建丰富索引,然后从中丰富目标索引。 The source and destination index can be the same, which would work in your case.源索引和目标索引可以相同,这适用于您的情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM