# Merge fields between documents

**URL:** <https://discuss.elastic.co/t/merge-fields-between-documents/303525>\
**Category:** Elasticsearch\
**Tags:** eql-elastic-query-language\
**Created:** [April 28, 2022, 2:34pm UTC](https://discuss.elastic.co/t/merge-fields-between-documents/303525 "2022-04-28T14:34:34Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [April 28, 2022, 4:05pm UTC](https://discuss.elastic.co/t/merge-fields-between-documents/303525/2 "2022-04-28T16:05:43Z")

</div>

Hi!

I think you should do this merge on the application side but I send the post below, hope it helps.

> [@Combine multiple document into one document with limited Fields ( merging of documents )](https://discuss.elastic.co/t/combine-multiple-document-into-one-document-with-limited-fields-merging-of-documents/231758/6):
>
> You can use a [transform](https://www.elastic.co/guide/en/elasticsearch/reference/7.7/transforms.html) for it. The group\_by must be based on a common criteria, e.g. a common id. For the combining step, you can use a scripted metric, e.g.: "all\_docs": { "scripted\_metric": { "init\_script": "state.docs = []", "map\_script": "state.docs.add(new HashMap(params['\_source']))", "combine\_script": "return state.docs", "reduce\_script": "def docs = []; for (s in states) {for (d in s) { docs.add(d);}}return docs" } } this would create an array with the original do…

---

_[View the full topic](https://discuss.elastic.co/t/merge-fields-between-documents/303525)._
