# Dictionary for my events in Elasticsearch

**URL:** <https://discuss.elastic.co/t/dictionary-for-my-events-in-elasticsearch/142114>\
**Category:** Logstash\
**Created:** [July 30, 2018, 7:49am UTC](https://discuss.elastic.co/t/dictionary-for-my-events-in-elasticsearch/142114 "2018-07-30T07:49:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sakshi\_Aggarwal](https://avatars.discourse-cdn.com/v4/letter/s/9e8a1a/32.png) [@Sakshi\_Aggarwal](https://discuss.elastic.co/u/Sakshi_Aggarwal)\
**Post date:** [July 30, 2018, 7:49am UTC](https://discuss.elastic.co/t/dictionary-for-my-events-in-elasticsearch/142114/1 "2018-07-30T07:49:52Z")

</div>

Currently I have the following scenario 🙂

 ![fixwhat](https://us1.discourse-cdn.com/elastic/original/3X/3/c/3c9ccde6b4395d6c7427bacf8e8606d688621251.png)

I want to dynamically insert a dictionary that replaces the field name , for example, 128 to trade name and similarly others.  
I have around 400 such fields.  
So I cant hardcode every fieldname .  
Suggest me a way to insert the dictinary dynamically.

Thanks,  
Regards  
Sakshi Aggarwal.

---

<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 30, 2018, 1:50pm UTC](https://discuss.elastic.co/t/dictionary-for-my-events-in-elasticsearch/142114/2 "2018-07-30T13:50:51Z")

</div>

Interesting question! I would do that using ruby.

First, create a JSON dictionary that contains the mapping of field names. For example:

```
{
"1": "TradeName",
"2": "Foo",
"3": "bar"
}

```

Then use a ruby filter to do the lookups

```
    ruby {
        init => '@d = JSON.parse( File.read( "/path/to/dictionary.json" ) )'
        code => '
            event.to_hash.each { |k, v|
                if @d.has_key?(k)
                    event.set(@d[k], v)
                    event.remove(k)
                end
            }
        '
    }

```

Error handling is left as an exercise for the reader.

---

<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 27, 2018, 1:51pm UTC](https://discuss.elastic.co/t/dictionary-for-my-events-in-elasticsearch/142114/3 "2018-08-27T13:51:05Z")

</div>

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