# How to create array data type from CSV

**URL:** <https://discuss.elastic.co/t/how-to-create-array-data-type-from-csv/139179>\
**Category:** Logstash\
**Created:** [July 9, 2018, 1:25pm UTC](https://discuss.elastic.co/t/how-to-create-array-data-type-from-csv/139179 "2018-07-09T13:25:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![eviatenne](https://avatars.discourse-cdn.com/v4/letter/e/bbce88/32.png) [@eviatenne](https://discuss.elastic.co/u/eviatenne)\
**Post date:** [July 9, 2018, 1:25pm UTC](https://discuss.elastic.co/t/how-to-create-array-data-type-from-csv/139179/1 "2018-07-09T13:25:07Z")

</div>

Hey, let's assume I have the following CSV and I would like to populate it into world\_cup\_2018 index

csv: groups.csv  
Group A|Uruguay,Russia,Saudi Arabia,Egypt  
Group B|Spain,Portugal,Iran,Morocco  
....

I would like to create the following fields on my index:  
group\_name:string  
teams: array

My logstash script:

* * *

input  
{  
file{  
start\_position =\> "beginning"  
path =\> "/home/groups.csv"  
"sincedb\_path" =\> "/dev/null"  
}  
}

filter  
{  
csv {  
separator =\> "|"  
columns =\> [  
'group\_name',  
'teams'  
]  
}  
}

output  
{  
elasticsearch {  
hosts =\> ["[https://localhost:9243](https://localhost:9243)"]  
index =\> ["world\_cup\_2018"]  
manage\_template =\> false  
}  
stdout { codec =\> "rubydebug" }  
#stdout { codec =\> "dots" }  
}

* * *

Is it possible? If yes, what should I change in this script in order to convert teams field into an array, with comma as my separator?

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:** [July 9, 2018, 1:28pm UTC](https://discuss.elastic.co/t/how-to-create-array-data-type-from-csv/139179/2 "2018-07-09T13:28:19Z")

</div>

You can do that using a [mutate+split](https://www.elastic.co/guide/en/logstash/current/plugins-filters-mutate.html#plugins-filters-mutate-split) operator.

---

<div class="post-metadata">

**Author:** ![eviatenne](https://avatars.discourse-cdn.com/v4/letter/e/bbce88/32.png) [@eviatenne](https://discuss.elastic.co/u/eviatenne)\
**Post date:** [July 9, 2018, 7:27pm UTC](https://discuss.elastic.co/t/how-to-create-array-data-type-from-csv/139179/3 "2018-07-09T19:27:16Z")

</div>

This is exactly what I was looking for, thanks 🙂

---

<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:** [August 6, 2018, 7:27pm UTC](https://discuss.elastic.co/t/how-to-create-array-data-type-from-csv/139179/4 "2018-08-06T19:27:18Z")

</div>

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