# Using csv file as dictionary for translate plugin

**URL:** https://discuss.elastic.co/t/using-csv-file-as-dictionary-for-translate-plugin/185069
**Category:** Logstash
**Created:** [June 10, 2019, 10:38pm UTC](https://discuss.elastic.co/t/using-csv-file-as-dictionary-for-translate-plugin/185069 "2019-06-10T22:38:52Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![leeyu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leeyu/32/48561_2.png) [@leeyu](https://discuss.elastic.co/u/leeyu)
#### Post date: [June 10, 2019, 10:38pm UTC](https://discuss.elastic.co/t/using-csv-file-as-dictionary-for-translate-plugin/185069/1 "2019-06-10T22:38:52Z")

</div>

Hi all,

I am new to elastic.  
Today I was trying to perform translate on a csv file.  
Including the dictionary in the conf works fine but logstash always shut down if I try to load the dictionary from a csv file.

Can anyone help me with this issue?  
Thanks

My translate code  
\</\>  
translate {  
dictionary\_path =\> "/data/ELK\_data/map.csv"  
field =\> "event\_id"  
destination =\> "event\_name"  
}  
\</\>

map.csv  
\</\>  
event\_id, event\_name  
1,"Event #1"  
2,"Event #2"  
3,"Event #3"  
4,"Event #4"  
\</\>

target.csv  
\</\>  
id,event\_id  
1,4  
2,3  
3,2  
4,1  
\</\>

---

<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: [June 11, 2019, 12:58am UTC](https://discuss.elastic.co/t/using-csv-file-as-dictionary-for-translate-plugin/185069/2 "2019-06-11T00:58:05Z")

</div>

Did you parse your CSV file using

```
csv { columns => ["id", "event_id"] }
```

---

<div class="post-metadata">

### Author: ![leeyu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leeyu/32/48561_2.png) [@leeyu](https://discuss.elastic.co/u/leeyu)
#### Post date: [June 11, 2019, 1:12am UTC](https://discuss.elastic.co/t/using-csv-file-as-dictionary-for-translate-plugin/185069/3 "2019-06-11T01:12:24Z")

</div>

Hi Badger,  
Thanks for reply,  
I used autodetect\_column\_names and autogenerate\_column\_names.  
I think there should be sth wrong with my csv.

---

<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: [June 11, 2019, 1:32am UTC](https://discuss.elastic.co/t/using-csv-file-as-dictionary-for-translate-plugin/185069/4 "2019-06-11T01:32:29Z")

</div>

Can you post a complete example of a configuration that is reproducible. \</\> is not markdown, it is an icon on the toolbar that tells the browser to apply markdown. If you select a multiline block of text then clicking on \</\> will indent the text by 4 spaces and change

event\_id, event\_name  
1,"Event #1"  
2,"Event #2"  
3,"Event #3"  
4,"Event #4"

to

```
event_id, event_name
1,"Event #1"
2,"Event #2"
3,"Event #3"
4,"Event #4"

```

This matters a lot when your data, for example, has multiple spaces. It is the difference between

Foo bar  
Baz ...

where the browser compresses multiple spaces into one, and

```
Foo bar
Baz ...

```

and sometimes spaces (or tabs) matter a lot. \</\> does not work on single lines.

---

<div class="post-metadata">

### Author: ![leeyu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leeyu/32/48561_2.png) [@leeyu](https://discuss.elastic.co/u/leeyu)
#### Post date: [June 11, 2019, 1:36am UTC](https://discuss.elastic.co/t/using-csv-file-as-dictionary-for-translate-plugin/185069/5 "2019-06-11T01:36:30Z")

</div>

I apologize for the inconvenience. Here should be sufficient.

filter

```
filter{
  csv {
      autodetect_column_names => "true"
      autogenerate_column_names => "true"
      skip_header => "true"
      separator => ","
   }

  translate {
    field => "event_id"
    destination => "event_name"
    override => true
    dictionary_path => ["/data/mapping-table/map_v2.csv"]
   } 
}

```

map\_v2.csv

```
1, Event1
2, Event2
3, Event3
4, Event4

```

target.csv

```
id, event_id
1, 4
2, 3
3, 2
4, 1
```

---

<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: [June 11, 2019, 2:08am UTC](https://discuss.elastic.co/t/using-csv-file-as-dictionary-for-translate-plugin/185069/6 "2019-06-11T02:08:26Z")

</div>

Great response! I don't think you have a field called [event\_id]. I think you have a field called

```
[event_id]

```

with an imbedded space. I do not have time to check right now, but it is possible that changing the option on your translate filter to

```
field => " event_id"

```

would make it work, and fixing up your CSV files would probably be a better approach.

---

<div class="post-metadata">

### Author: ![leeyu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leeyu/32/48561_2.png) [@leeyu](https://discuss.elastic.co/u/leeyu)
#### Post date: [June 11, 2019, 2:26am UTC](https://discuss.elastic.co/t/using-csv-file-as-dictionary-for-translate-plugin/185069/7 "2019-06-11T02:26:48Z")

</div>

Haha, I also have no access to the server right now.  
I will be able to verify it tomorrow.  
Thank you very much!!!

---

<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: [July 9, 2019, 2:26am UTC](https://discuss.elastic.co/t/using-csv-file-as-dictionary-for-translate-plugin/185069/8 "2019-07-09T02:26:58Z")

</div>

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