# Generating multiple events from a single message

**URL:** <https://discuss.elastic.co/t/generating-multiple-events-from-a-single-message/108772>\
**Category:** Logstash\
**Created:** [November 22, 2017, 5:26pm UTC](https://discuss.elastic.co/t/generating-multiple-events-from-a-single-message/108772 "2017-11-22T17:26:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pri](https://avatars.discourse-cdn.com/v4/letter/p/22d042/32.png) [@pri](https://discuss.elastic.co/u/pri)\
**Post date:** [November 22, 2017, 5:26pm UTC](https://discuss.elastic.co/t/generating-multiple-events-from-a-single-message/108772/1 "2017-11-22T17:26:08Z")

</div>

Hi,

I have a csv file that looks like this: The first line is the header column

**Item, Type, Category, Q1, Q2, Q3, Q4**  
Tools, License, Cost Saving, 15000, 0, 6000, 899

I am trying to consume this in Logstash and send the resulting events/documents to elasticsearch. The overall functionality works but what I want is to generate 4 events /documents from each row like this:

Item: Tools  
Category: Cost Saving  
Type: License  
Quarter: Q1  
Quarter1\_Value : 15000

Item: Tools  
Category: Cost Saving  
Type: License  
Quarter: Q2  
Quarter2Value: 0

and so on for Q3 and Q4 too.

My csv filter currently looks like this:  
filter {  
csv {  
columns =\> ["item","category","type","q1","q2", "q3", "q4"]  
add\_field =\> {  
"quarter" =\> "q1"  
"amount" =\> "%{q1}"  
}  
}  
}

But what I am missing is a way to generate 4 events from one single row. Is this possible? And is there another filter that I have to use to accomplish this? I am new to Logstash and any help is greatly appreciated.

Thanks

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [November 22, 2017, 6:24pm UTC](https://discuss.elastic.co/t/generating-multiple-events-from-a-single-message/108772/2 "2017-11-22T18:24:20Z")

</div>

It does not do what you want, but this might get you started...

```
filter {
  mutate { gsub => ["message", ", ", ","] }
  csv { autodetect_column_names => true }
  ruby { code => "event.set('Qs', [event.get('Q1') , event.get('Q2') , event.get('Q3') , event.get('Q4')] )" }
  split { field => "Qs" }
}
```

Actually you could add

```
if [Q1] == [Qs] { mutate { add_field => { "Quarter" => "Q1" } } }
  if [Q2] == [Qs] { mutate { add_field => { "Quarter" => "Q2" } } }
  if [Q3] == [Qs] { mutate { add_field => { "Quarter" => "Q3" } } }
  if [Q4] == [Qs] { mutate { add_field => { "Quarter" => "Q4" } } }
```

to that and it would do pretty much what you want. But looking at a filter that ugly might make your eyes bleed 🙂 Probably also need to mutate / remove\_field some stuff.

```
mutate { remove_field => ["Q1", "Q2", "Q3", "Q4"] }
```

---

<div class="post-metadata">

**Author:** ![pri](https://avatars.discourse-cdn.com/v4/letter/p/22d042/32.png) [@pri](https://discuss.elastic.co/u/pri)\
**Post date:** [November 22, 2017, 9:05pm UTC](https://discuss.elastic.co/t/generating-multiple-events-from-a-single-message/108772/3 "2017-11-22T21:05:00Z")

</div>

Thank you so much. Will try the suggestion and get back to you.

---

<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:** [December 20, 2017, 9:05pm UTC](https://discuss.elastic.co/t/generating-multiple-events-from-a-single-message/108772/4 "2017-12-20T21:05:16Z")

</div>

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