# Convert number to string

**URL:** <https://discuss.elastic.co/t/convert-number-to-string/113004>\
**Category:** Kibana\
**Created:** [December 22, 2017, 1:09pm UTC](https://discuss.elastic.co/t/convert-number-to-string/113004 "2017-12-22T13:09:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jali](https://avatars.discourse-cdn.com/v4/letter/j/ecae2f/32.png) [@jali](https://discuss.elastic.co/u/jali)\
**Post date:** [December 22, 2017, 1:09pm UTC](https://discuss.elastic.co/t/convert-number-to-string/113004/1 "2017-12-22T13:09:33Z")

</div>

Hello,  
I have a number field ('response') with values ranging between 0-2. I need to do scripted field which converts these number to string values. 0=Bad, 1=OK, 2=Excellent. How do I do that?

I am trying:  
if (doc['response'].value = 0) { return "Bad"; }  
if (doc['response'].value = 1) { return "OK"; }  
if (doc['resonnse'].value = 2) { return "Excellent"; }  
return "";

However this is not working .  
I get errors '_._..."compile error","script\_stack":["if (doc .........lang":"painless","caused\_by":{"type":"class\_cast\_exception","reason":"Cannot cast from [int] to [boolean]."}}}]},"status":500}......'\_

---

<div class="post-metadata">

**Author:** ![a5a](https://avatars.discourse-cdn.com/v4/letter/a/a87d85/32.png) [@a5a](https://discuss.elastic.co/u/a5a)\
**Post date:** [December 22, 2017, 4:54pm UTC](https://discuss.elastic.co/t/convert-number-to-string/113004/2 "2017-12-22T16:54:52Z")

</div>

Hi jali,

I'm not a painless expert, but can you just try `==` instead of `=` in your `if` statements?

---

<div class="post-metadata">

**Author:** ![jali](https://avatars.discourse-cdn.com/v4/letter/j/ecae2f/32.png) [@jali](https://discuss.elastic.co/u/jali)\
**Post date:** [December 22, 2017, 8:56pm UTC](https://discuss.elastic.co/t/convert-number-to-string/113004/3 "2017-12-22T20:56:14Z")

</div>

And... it works! Thanks!!

---

<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:** [January 19, 2018, 8:56pm UTC](https://discuss.elastic.co/t/convert-number-to-string/113004/4 "2018-01-19T20:56:15Z")

</div>

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