# Logstash - list of codes to replace

**URL:** https://discuss.elastic.co/t/logstash-list-of-codes-to-replace/163767
**Category:** Logstash
**Created:** [January 10, 2019, 3:22pm UTC](https://discuss.elastic.co/t/logstash-list-of-codes-to-replace/163767 "2019-01-10T15:22:23Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Francisca\_Lima](https://avatars.discourse-cdn.com/v4/letter/f/edb3f5/32.png) [@Francisca\_Lima](https://discuss.elastic.co/u/Francisca_Lima)
#### Post date: [January 10, 2019, 3:22pm UTC](https://discuss.elastic.co/t/logstash-list-of-codes-to-replace/163767/1 "2019-01-10T15:22:23Z")

</div>

Hello,  
I want to match my data with a set of codes. I tried to do that using translate plugin, having a file with those matches. But, it seems a bad option because I have various matches with lead me to have many auxiliary files. There is any other way to do this?

Thank you.

---

<div class="post-metadata">

### Author: ![Chris\_Lyons](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chris_lyons/32/48107_2.png) [@Chris\_Lyons](https://discuss.elastic.co/u/Chris_Lyons)
#### Post date: [January 12, 2019, 12:44am UTC](https://discuss.elastic.co/t/logstash-list-of-codes-to-replace/163767/2 "2019-01-12T00:44:40Z")

</div>

If you are comfortable using the ruby filter you can leverage ruby case statements. Something we do to translate code\_values to display\_values in our pipeline.

Example from our external ruby file:

> def filter(event)  
> case event.get('field1')  
> when 0 then event.set('shifts', 'Yes')  
> when 1 then event.set('shifts', 'No')  
> end
> 
> case event.get('field2')  
> when 0 then event.set('view\_access', 'Internal')  
> when 1 then event.set('view\_access', 'Public')  
> end
> 
> case event.get('field3')  
> when 0 then event.set('locked', 'Yes')  
> when 1 then event.set('locked', 'No')  
> end
> 
> case event.get('field4')  
> when 0 then event.set('action\_status', 'Assigned')  
> when 1 then event.set('action\_status', 'In Progress')  
> when 2 then event.set('action\_status', 'Completed')  
> end
> 
> case event.get('field5')  
> when 0 then event.set('assign\_work\_detail', 'Yes')  
> when 1 then event.set('assign\_work\_detail', 'No')  
> end
> 
> return [event]  
> end

---

<div class="post-metadata">

### Author: ![Francisca\_Lima](https://avatars.discourse-cdn.com/v4/letter/f/edb3f5/32.png) [@Francisca\_Lima](https://discuss.elastic.co/u/Francisca_Lima)
#### Post date: [January 15, 2019, 10:07am UTC](https://discuss.elastic.co/t/logstash-list-of-codes-to-replace/163767/3 "2019-01-15T10:07:24Z")

</div>

Thank you. However when I have a large quantity of combinations, is this type of conditions more efficient than having translate filter? Which one is the better option?

---

<div class="post-metadata">

### Author: ![Chris\_Lyons](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chris_lyons/32/48107_2.png) [@Chris\_Lyons](https://discuss.elastic.co/u/Chris_Lyons)
#### Post date: [January 15, 2019, 1:39pm UTC](https://discuss.elastic.co/t/logstash-list-of-codes-to-replace/163767/4 "2019-01-15T13:39:52Z")

</div>

Honestly I do not know but we have not noticed any latency issues. The translate option for us would produce a pretty nasty pipeline given some of our ruby filters have 20+ fields that get converted. I enjoy the manageability of the ruby (1 file per pipeline).

---

<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: [February 12, 2019, 1:40pm UTC](https://discuss.elastic.co/t/logstash-list-of-codes-to-replace/163767/5 "2019-02-12T13:40:18Z")

</div>

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