# Merge information from two different lines into single event

**URL:** https://discuss.elastic.co/t/merge-information-from-two-different-lines-into-single-event/77791
**Category:** Logstash
**Created:** [March 8, 2017, 9:37am UTC](https://discuss.elastic.co/t/merge-information-from-two-different-lines-into-single-event/77791 "2017-03-08T09:37:44Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Tarun\_Kalluri](https://avatars.discourse-cdn.com/v4/letter/t/e9a140/32.png) [@Tarun\_Kalluri](https://discuss.elastic.co/u/Tarun_Kalluri)
#### Post date: [March 8, 2017, 9:37am UTC](https://discuss.elastic.co/t/merge-information-from-two-different-lines-into-single-event/77791/1 "2017-03-08T09:37:44Z")

</div>

I have a log file which has product id and item sale details on different lines. An example file can be

**useless info**  
**product id: 2455**  
**useless info**  
**Customer Name: xyz1 Price : abc1 Profit: efg1**  
**Customer Name: xyz2 Price : abc2 Profit: efg2**  
**Customer Name: xyz3 Price : abc3 Profit: efg3.**  
**useless info**

Now, my requirement is that along with name, price and profit, I also need the product id into my elastic search event data. One way to do this is to find the id and append it to all the lines in the file, but I am looking at a more elegant way to do this using only logstash. I have tried using multiple matching in grok, but it is only _separately_ parsing the lines, but I am looking at someway which would retain information from previous lines.

---

<div class="post-metadata">

### Author: ![Conall\_Prendergast](https://avatars.discourse-cdn.com/v4/letter/c/d26b3c/32.png) [@Conall\_Prendergast](https://discuss.elastic.co/u/Conall_Prendergast)
#### Post date: [March 8, 2017, 10:34am UTC](https://discuss.elastic.co/t/merge-information-from-two-different-lines-into-single-event/77791/2 "2017-03-08T10:34:27Z")

</div>

Hi @Tarun_Kalluri,

This is an ideal case for the [aggregate filter](https://www.elastic.co/guide/en/logstash/current/plugins-filters-aggregate.html) in Logstash.  
In this case, you could use the "product id" as the task id I guess

---

<div class="post-metadata">

### Author: ![Tarun\_Kalluri](https://avatars.discourse-cdn.com/v4/letter/t/e9a140/32.png) [@Tarun\_Kalluri](https://discuss.elastic.co/u/Tarun_Kalluri)
#### Post date: [March 9, 2017, 7:07am UTC](https://discuss.elastic.co/t/merge-information-from-two-different-lines-into-single-event/77791/3 "2017-03-09T07:07:23Z")

</div>

Hi Conall, thanks for the suggestion. But as I understand it, aggregate filter needs to have some _common_ field(s) among different lines to join them together, correct me if I am wrong. But here, one line contains product\_id and nothing else, and line containing customer details does not contain id. The id, however, is unique to a file, so I need to copy on that information to all the further lines.

---

<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: [April 6, 2017, 7:07am UTC](https://discuss.elastic.co/t/merge-information-from-two-different-lines-into-single-event/77791/4 "2017-04-06T07:07:29Z")

</div>

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