# Continuously merging documents from multiple indexes

**URL:** https://discuss.elastic.co/t/continuously-merging-documents-from-multiple-indexes/279953
**Category:** Elasticsearch
**Created:** [July 29, 2021, 8:16am UTC](https://discuss.elastic.co/t/continuously-merging-documents-from-multiple-indexes/279953 "2021-07-29T08:16:43Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![Hendrik\_Muhs](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hendrik_muhs/32/25802_2.png) [@Hendrik\_Muhs](https://discuss.elastic.co/u/Hendrik_Muhs)
#### Post date: [July 29, 2021, 9:25am UTC](https://discuss.elastic.co/t/continuously-merging-documents-from-multiple-indexes/279953/2 "2021-07-29T09:25:07Z")

</div>

You can use a continuous [transform](https://www.elastic.co/guide/en/elasticsearch/reference/current/transforms.html) for this, however you need 2, one that groups by `userId` and a 2nd one that merges the output of the 1st transform with topic3 by grouping on `externalId`.

However for a continuous transform all your source indexes require timestamp field, if you don't have one you might [add one using an ingest timestamp](https://discuss.elastic.co/t/dec-12th-2018-en-elasticsearch-automatically-adding-a-timestamp-to-documents/159314). You also need this to connect transform 1 with transform 2.

For picking the right values for the output, e.g. `email` you can use a script via `scripted_metric` (spoiler: in a future release this will become easier). Have a look at the provided docs, in the sub sections you will find some painless examples, e.g. the one for [top\_hits](https://www.elastic.co/guide/en/elasticsearch/reference/current/transform-painless-examples.html#painless-top-hits).

---

_[View the full topic](https://discuss.elastic.co/t/continuously-merging-documents-from-multiple-indexes/279953)._
