# Creating a new field based on the input and send it to the output

**URL:** <https://discuss.elastic.co/t/creating-a-new-field-based-on-the-input-and-send-it-to-the-output/207915>\
**Category:** Logstash\
**Created:** [November 14, 2019, 2:48pm UTC](https://discuss.elastic.co/t/creating-a-new-field-based-on-the-input-and-send-it-to-the-output/207915 "2019-11-14T14:48:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Avinaba\_Ghosh\_Hajra](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/avinaba_ghosh_hajra/32/57697_2.png) [@Avinaba\_Ghosh\_Hajra](https://discuss.elastic.co/u/Avinaba_Ghosh_Hajra)\
**Post date:** [November 14, 2019, 2:48pm UTC](https://discuss.elastic.co/t/creating-a-new-field-based-on-the-input-and-send-it-to-the-output/207915/1 "2019-11-14T14:48:24Z")

</div>

I have a simple query that fetch data from database through logstash jdbc plugin.  
Query : Select emp\_id, department\_id from employee;  
Now I need an addition field department\_name in the output.  
department\_name can be created based on department\_id and simple logic (  
if ( department\_id = '1') {  
department\_name = "ABC"  
} else if ( department\_id = '2') {  
department\_name = "DEF  
} else if ( department\_id = '3') {  
department\_name = "GHI"  
}

How to achieve this?

---

<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:** [November 14, 2019, 3:02pm UTC](https://discuss.elastic.co/t/creating-a-new-field-based-on-the-input-and-send-it-to-the-output/207915/2 "2019-11-14T15:02:00Z")

</div>

You could use an if-else like that and use mutate+add\_field, or you could use a translate filter.

---

<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:** [December 12, 2019, 3:02pm UTC](https://discuss.elastic.co/t/creating-a-new-field-based-on-the-input-and-send-it-to-the-output/207915/3 "2019-12-12T15:02:05Z")

</div>

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