# How to merge two document in logstash

**URL:** https://discuss.elastic.co/t/how-to-merge-two-document-in-logstash/232531
**Category:** Logstash
**Created:** [May 14, 2020, 1:47am UTC](https://discuss.elastic.co/t/how-to-merge-two-document-in-logstash/232531 "2020-05-14T01:47:26Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![CambridgeLv](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cambridgelv/32/68293_2.png) [@CambridgeLv](https://discuss.elastic.co/u/CambridgeLv)
#### Post date: [May 14, 2020, 1:47am UTC](https://discuss.elastic.co/t/how-to-merge-two-document-in-logstash/232531/1 "2020-05-14T01:47:26Z")

</div>

Hi, I am using ELK to visualize the data in logs. Is it possible to merge two documents into one? As I know, each line from filebeat will make one doc output to elasticsearch(or with multi-lines input, then multi-lines will make one doc, but my situation is from different files). To be specific, I have one doc with fields A, B ; Another doc with fields A, C ;How to make new doc with fields A, B, C and remove previous two docs?

By the way, all I want to do is to create the visualization of B/C (B divided by C), so if there is any possible way to do this by Kibana/Elasticsearch is also okey.

---

<div class="post-metadata">

### Author: ![andres-perez](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andres-perez/32/136461_2.png) [@andres-perez](https://discuss.elastic.co/u/andres-perez)
#### Post date: [May 14, 2020, 7:01pm UTC](https://discuss.elastic.co/t/how-to-merge-two-document-in-logstash/232531/2 "2020-05-14T19:01:48Z")

</div>

Can you give more details about your use case?

How do the 2 documents from your example relate to each other?

Is there a unique _id_ value for common to both documents and different to any other document pairs that you use for your calculations?

You may use [aggregate](https://www.elastic.co/guide/en/logstash/current/plugins-filters-aggregate.html) filter to join documents before indexing, enrich them using the already present data from [elasticsearch](https://www.elastic.co/guide/en/logstash/7.6/plugins-filters-elasticsearch.html), configure the output with [upsert](https://www.elastic.co/guide/en/logstash/7.6/plugins-outputs-elasticsearch.html#plugins-outputs-elasticsearch-upsert) using or constructing an _id_ when indexing...

There are multiple approaches with their own pros and cons - the more detailed information you add, the better answers you will get 🙂

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [June 11, 2020, 7:02pm UTC](https://discuss.elastic.co/t/how-to-merge-two-document-in-logstash/232531/3 "2020-06-11T19:02:07Z")

</div>

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