# Add a field, when indexing, with string representation of another integer field

**URL:** <https://discuss.elastic.co/t/add-a-field-when-indexing-with-string-representation-of-another-integer-field/205957>\
**Category:** Elasticsearch\
**Created:** [October 30, 2019, 10:35pm UTC](https://discuss.elastic.co/t/add-a-field-when-indexing-with-string-representation-of-another-integer-field/205957 "2019-10-30T22:35:00Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![NiclasK](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/niclask/32/47189_2.png) [@NiclasK](https://discuss.elastic.co/u/NiclasK)\
**Post date:** [October 30, 2019, 10:35pm UTC](https://discuss.elastic.co/t/add-a-field-when-indexing-with-string-representation-of-another-integer-field/205957/1 "2019-10-30T22:35:00Z")

</div>

Hi,

I index data that contain a state which is represented as an integer. I would like to translate this number into a string which is easier to remember and search for. What is the recommended way to do this?

Example:  
State.Current: 5  
I would like to add a field with the string representation:  
State.Current.Text: ST\_IDLE

Thanks

---

<div class="post-metadata">

**Author:** ![nishant.saini](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nishant.saini/32/41489_2.png) [@nishant.saini](https://discuss.elastic.co/u/nishant.saini)\
**Post date:** [October 31, 2019, 3:01am UTC](https://discuss.elastic.co/t/add-a-field-when-indexing-with-string-representation-of-another-integer-field/205957/2 "2019-10-31T03:01:56Z")

</div>

Is State a nested type field or plain object field?

---

<div class="post-metadata">

**Author:** ![NiclasK](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/niclask/32/47189_2.png) [@NiclasK](https://discuss.elastic.co/u/NiclasK)\
**Post date:** [October 31, 2019, 8:21am UTC](https://discuss.elastic.co/t/add-a-field-when-indexing-with-string-representation-of-another-integer-field/205957/3 "2019-10-31T08:21:20Z")

</div>

The data I index look like this:  
{  
...  
"State":{  
"Current": 1  
}  
...  
}

But it is indexed as a number with fieldname  
State.Current

---

<div class="post-metadata">

**Author:** ![nishant.saini](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nishant.saini/32/41489_2.png) [@nishant.saini](https://discuss.elastic.co/u/nishant.saini)\
**Post date:** [November 5, 2019, 12:15pm UTC](https://discuss.elastic.co/t/add-a-field-when-indexing-with-string-representation-of-another-integer-field/205957/4 "2019-11-05T12:15:37Z")

</div>

By data representation it can't be ascertained whether the data type is object or nested. Please show the mapping of your index.

---

<div class="post-metadata">

**Author:** ![NiclasK](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/niclask/32/47189_2.png) [@NiclasK](https://discuss.elastic.co/u/NiclasK)\
**Post date:** [November 7, 2019, 11:45am UTC](https://discuss.elastic.co/t/add-a-field-when-indexing-with-string-representation-of-another-integer-field/205957/5 "2019-11-07T11:45:45Z")

</div>

I extracted the relevant part of the mapping:  
{  
"mapping": {  
"doc": {  
"properties": {  
"data": {  
"properties": {  
"state": {  
"properties": {  
"current": {  
"type": "long"  
},  
"previous": {  
"type": "long"  
}  
}  
}  
}  
}  
}  
}  
}  
}

---

<div class="post-metadata">

**Author:** ![NiclasK](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/niclask/32/47189_2.png) [@NiclasK](https://discuss.elastic.co/u/NiclasK)\
**Post date:** [November 27, 2019, 8:33pm UTC](https://discuss.elastic.co/t/add-a-field-when-indexing-with-string-representation-of-another-integer-field/205957/6 "2019-11-27T20:33:44Z")

</div>

Any ideas?

---

<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 25, 2019, 8:33pm UTC](https://discuss.elastic.co/t/add-a-field-when-indexing-with-string-representation-of-another-integer-field/205957/7 "2019-12-25T20:33:48Z")

</div>

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