# How to add count value to each csv value in logstash

**URL:** <https://discuss.elastic.co/t/how-to-add-count-value-to-each-csv-value-in-logstash/268770>\
**Category:** Logstash\
**Created:** [March 30, 2021, 10:22am UTC](https://discuss.elastic.co/t/how-to-add-count-value-to-each-csv-value-in-logstash/268770 "2021-03-30T10:22:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ofitz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ofitz/32/47071_2.png) [@ofitz](https://discuss.elastic.co/u/ofitz)\
**Post date:** [March 30, 2021, 10:22am UTC](https://discuss.elastic.co/t/how-to-add-count-value-to-each-csv-value-in-logstash/268770/1 "2021-03-30T10:22:50Z")

</div>

I have some csv, and with ruby i convert it to array , like this:

```
11;22;33;44;55
66;77;88;99;100

 ruby {
     code => '
         m = event.get("message").split(";")
         m.each_index { |x| m[x] = m[x].to_f }
         event.set("[messages]", m)
     '
 }

```

Output is:

```
"hits" : [
  {
    "_index" : "array_werte_v1",
    "_type" : "_doc",
    "_id" : "6pKOgngBVrDB9qxVPT4F",
    "_score" : 1.0,
    "_source" : {
      "path" : "/home/ofitz-elk/bueltmann/stab001/array_werte.csv",
      "column1" : "66;77;88;99;100",
      "host" : "ofitz_elk-ingest-node_0321",
      "@version" : "1",
      "@timestamp" : "2021-03-30T09:54:22.590Z",
      "message" : [
        66.0,
        77.0,
        88.0,
        99.0,
        100.0
      ]

```

i need additional array wit the count values of the array **message** like new field **"message\_count"** :

```
    "hits" : [
    {
    "_index" : "array_werte_v1",
    "_type" : "_doc",
    "_id" : "6pKOgngBVrDB9qxVPT4F",
    "_score" : 1.0,
    "_source" : {
      "path" : array_werte.csv",
      "column1" : "66;77;88;99;100",
      "host" : "host_0321",
      "@version" : "1",
      "@timestamp" : "2021-03-30T09:54:22.590Z",
      "message" : [66.0, 77.0, 88.0, 99.0, 100.0],
      "message_count" : [1, 2, 3, 4, 5]
 ]
```

---

<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 27, 2021, 10:23am UTC](https://discuss.elastic.co/t/how-to-add-count-value-to-each-csv-value-in-logstash/268770/2 "2021-04-27T10:23:26Z")

</div>

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