# Should I store strings directly or their numeric tokens in elasticsearch

**URL:** <https://discuss.elastic.co/t/should-i-store-strings-directly-or-their-numeric-tokens-in-elasticsearch/98438>\
**Category:** Elasticsearch\
**Created:** [August 26, 2017, 5:48am UTC](https://discuss.elastic.co/t/should-i-store-strings-directly-or-their-numeric-tokens-in-elasticsearch/98438 "2017-08-26T05:48:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fong\_Ng](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/fong_ng/32/21533_2.png) [@Fong\_Ng](https://discuss.elastic.co/u/Fong_Ng)\
**Post date:** [August 26, 2017, 5:48am UTC](https://discuss.elastic.co/t/should-i-store-strings-directly-or-their-numeric-tokens-in-elasticsearch/98438/1 "2017-08-26T05:48:30Z")

</div>

I can't decide which way to save an increasing number of event information to elasticsearch. Each filterable fields have a limited number of options, but multiple options are allowed. Should I store the information directly like this:

> {  
> "id":"1",  
> "name":"Event A",  
> "type":"Training,Workshop,Meeting",  
> "industrialSector":"Energy,Transport",  
> "country":"China"  
> // + 80 fields alike  
> }

Or use some backend work to turn the string values into numeric tokens before saving to elasticsearch:

> {  
> "id":"1",  
> "name":"Event A",  
> "type":"1 3 5",  
> "industrialSector":"2 3",  
> "country":"7"  
> // + 80 fields alike  
> }

There will be a map object to reference the field options before saved or after fetched:

> let options =  
> {  
> type:{  
> Training:1,  
> Fair:2  
> Workshop:3,  
> Brokerage:4  
> Meeting:5  
> },  
> industrialSector:{  
> Tech:1  
> Energy:2  
> Transport:3  
> }  
> }

The first one requires less work, but does it perform slower and require more diskspaces than the second one?

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [August 26, 2017, 9:19am UTC](https://discuss.elastic.co/t/should-i-store-strings-directly-or-their-numeric-tokens-in-elasticsearch/98438/2 "2017-08-26T09:19:14Z")

</div>

I'd think the second one would be slower cause of the extra translation step?

---

<div class="post-metadata">

**Author:** ![Fong\_Ng](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/fong_ng/32/21533_2.png) [@Fong\_Ng](https://discuss.elastic.co/u/Fong_Ng)\
**Post date:** [August 26, 2017, 9:54am UTC](https://discuss.elastic.co/t/should-i-store-strings-directly-or-their-numeric-tokens-in-elasticsearch/98438/3 "2017-08-26T09:54:23Z")

</div>

Yes, it requires some backend works to translate the numeric values into strings for the api. Do you think the second solution has no major benefits over the first one?

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [August 26, 2017, 10:03am UTC](https://discuss.elastic.co/t/should-i-store-strings-directly-or-their-numeric-tokens-in-elasticsearch/98438/4 "2017-08-26T10:03:26Z")

</div>

I don't think so.  
I mean you would save some disk space because your values are smaller, but I'd question the value of that given you now have to do that second translation, so you trade one "cost" for another one that is potentially bigger (cause you have to now maintain that code and the translation table).

---

<div class="post-metadata">

**Author:** ![Fong\_Ng](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/fong_ng/32/21533_2.png) [@Fong\_Ng](https://discuss.elastic.co/u/Fong_Ng)\
**Post date:** [August 26, 2017, 10:23am UTC](https://discuss.elastic.co/t/should-i-store-strings-directly-or-their-numeric-tokens-in-elasticsearch/98438/5 "2017-08-26T10:23:50Z")

</div>

Thanks warkolm. Good suggestions. The first solution is the way to go.

---

<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:** [September 23, 2017, 10:24am UTC](https://discuss.elastic.co/t/should-i-store-strings-directly-or-their-numeric-tokens-in-elasticsearch/98438/6 "2017-09-23T10:24:15Z")

</div>

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