# Merge 2 index based off fields and not rows

**URL:** <https://discuss.elastic.co/t/merge-2-index-based-off-fields-and-not-rows/292706>\
**Category:** Kibana\
**Created:** [December 22, 2021, 3:15pm UTC](https://discuss.elastic.co/t/merge-2-index-based-off-fields-and-not-rows/292706 "2021-12-22T15:15:24Z")\
**Posts on this page:** 1\
**Showing post:** 3

<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:** [December 22, 2021, 3:27pm UTC](https://discuss.elastic.co/t/merge-2-index-based-off-fields-and-not-rows/292706/3 "2021-12-22T15:27:35Z")

</div>

Have a look at transforms, you can source both indexes, use a `pivot`, group on `terms` using the field `id`. For the output fields you have several options (just ideas, not verified):

- a `filter` aggregation and `top_metrics` as sub aggregation
- `top_metrics` on top, sort by `_index` ascending for index 1, descending to get index 2
- `scripted_metric`

You find further information in older posts: [How to join two index - #3 by Hendrik\_Muhs](https://discuss.elastic.co/t/how-to-join-two-index/274572/3)

Note however that these posts are old and e.g. `top_metrics` has been added just recently. I talk about `top_metrics` in a recent advent post: [Dec 11th, 2021: [en] On a road trip with Transform](https://discuss.elastic.co/t/dec-11th-2021-en-on-a-road-trip-with-transform/290532)

---

_[View the full topic](https://discuss.elastic.co/t/merge-2-index-based-off-fields-and-not-rows/292706)._
