# Dealing with multiple number of values from the same input - Logstash

**URL:** <https://discuss.elastic.co/t/dealing-with-multiple-number-of-values-from-the-same-input-logstash/266101>\
**Category:** Logstash\
**Created:** [March 3, 2021, 12:17pm UTC](https://discuss.elastic.co/t/dealing-with-multiple-number-of-values-from-the-same-input-logstash/266101 "2021-03-03T12:17:40Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![usman1](https://avatars.discourse-cdn.com/v4/letter/u/c67d28/32.png) [@usman1](https://discuss.elastic.co/u/usman1)\
**Post date:** [March 3, 2021, 12:17pm UTC](https://discuss.elastic.co/t/dealing-with-multiple-number-of-values-from-the-same-input-logstash/266101/1 "2021-03-03T12:17:40Z")

</div>

I have recently started using Logstash so still new at this. The use-case I am working on is that I want to ship a log file with Logstash that has different lengths of lines in it. The length of line (the number of attributes to be extracted) depends on a FLAG which is added right at the start of every line. To elaborate further, I have three flags and the log file contains lines similar to following:

FLAG1, TIMESTAMP, VAL1, VAL2, VAL3, VAL4, VAL6, VAL7, VAL8, VAL9  
FLAG2, TIMESTAMP, VAL1, VAL2, VAL3, VAL4, VAL6, VAL7  
FLAG3, TIMESTAMP, VAL1, VAL2, VAL3, VAL4, VAL6

Can someone explain how can I handle this in my filter section of config file?

---

<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:** [March 3, 2021, 7:57pm UTC](https://discuss.elastic.co/t/dealing-with-multiple-number-of-values-from-the-same-input-logstash/266101/2 "2021-03-03T19:57:52Z")

</div>

I would do something like [this](https://discuss.elastic.co/t/using-ruby-to-count-the-number-of-fields-in-a-message-then-apply-csv-depending-on-the-count/177880/2).

If all types of rows have the same fields (and FLAG2/FLAG3 rows are missing some) then you can use a single csv filter with the ignore\_empty\_columns set to true.

---

<div class="post-metadata">

**Author:** ![usman1](https://avatars.discourse-cdn.com/v4/letter/u/c67d28/32.png) [@usman1](https://discuss.elastic.co/u/usman1)\
**Post date:** [March 4, 2021, 10:07am UTC](https://discuss.elastic.co/t/dealing-with-multiple-number-of-values-from-the-same-input-logstash/266101/3 "2021-03-04T10:07:17Z")

</div>

Thanks for the response, @Badger.

But it seems like else block is not being running. Just a clarifying question, when we count the number of fields from metadata, does the code count number of fields in the CSV file or in the particular record?

---

<div class="post-metadata">

**Author:** ![usman1](https://avatars.discourse-cdn.com/v4/letter/u/c67d28/32.png) [@usman1](https://discuss.elastic.co/u/usman1)\
**Post date:** [March 4, 2021, 11:14am UTC](https://discuss.elastic.co/t/dealing-with-multiple-number-of-values-from-the-same-input-logstash/266101/4 "2021-03-04T11:14:52Z")

</div>

P.S. rows followed by different flags contain different fields altogether i.e. I will have to give them different column names after checking their flags or number of columns.

---

<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:** [March 4, 2021, 4:27pm UTC](https://discuss.elastic.co/t/dealing-with-multiple-number-of-values-from-the-same-input-logstash/266101/5 "2021-03-04T16:27:41Z")

</div>

> [@usman1](#):
>
> does the code count number of fields in the CSV file or in the particular record?

It counts it for each event (line), not for the file.

---

<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 1, 2021, 4:28pm UTC](https://discuss.elastic.co/t/dealing-with-multiple-number-of-values-from-the-same-input-logstash/266101/6 "2021-04-01T16:28:18Z")

</div>

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