# How to convert number to string using painless script and visualize it in kibana

**URL:** <https://discuss.elastic.co/t/how-to-convert-number-to-string-using-painless-script-and-visualize-it-in-kibana/158575>\
**Category:** Kibana\
**Created:** [November 28, 2018, 1:28pm UTC](https://discuss.elastic.co/t/how-to-convert-number-to-string-using-painless-script-and-visualize-it-in-kibana/158575 "2018-11-28T13:28:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![r.ganeshbabu](https://avatars.discourse-cdn.com/v4/letter/r/4da419/32.png) [@r.ganeshbabu](https://discuss.elastic.co/u/r.ganeshbabu)\
**Post date:** [November 28, 2018, 1:28pm UTC](https://discuss.elastic.co/t/how-to-convert-number-to-string-using-painless-script-and-visualize-it-in-kibana/158575/1 "2018-11-28T13:28:40Z")

</div>

Hi All,

I have a long field ('Powerstate') in index with values ranging between 0-1. I need to do scripted field which converts these number to string values. 0=OFF, 1=ON.

I am trying with the below script,

```
if (doc['PowerState'].value == 0) { 
    return "OFF"
} else {
    return "ON"
}

```

Below is the scripted field added in the index,

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/d/9/d93064298e2e0d8309bc0ff76e8ecf02fc672aa3.png)

I am trying to visualize the data with powerstate and device count as like below,

![image](https://us1.discourse-cdn.com/elastic/original/3X/4/1/41436888ade1d6ed2bf09cbdf440f26ead8c360d.png)

Since the powerstate value is either 0 or 1 and I want to show it as OFF or ON and I tried changing the original field to scripted field in the buckets and below is the exception showing,

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/4/9/49b2a181abf1b32919bbba5bb32473d716e269b3.png)

> :5601/bundles/vendors.bundle.js:197 RequestFailure "Possibly unhandled rejection: {"message":"Request to Elasticsearch failed: {"error":{"root\_cause":[{"type":"aggregation\_execution\_exception","reason":"Unsupported script value [OFF], expected a number, date, or boolean"}],"type":"search\_phase\_execution\_exception","reason":"all shards failed","phase":"query","grouped":true,"failed\_shards":[{"shard":0,"index":"staticinfo-2018.11","node":"ucDfjzdORoSIjMKnvthTmw","reason":{"type":"aggregation\_execution\_exception","reason":"Unsupported script value [OFF], expected a number, date, or boolean"}}]},"status":500}","origError":false,"resp":{"error":{"root\_cause":[{"type":"aggregation\_execution\_exception","reason":"Unsupported script value [OFF], expected a number, date, or boolean"}],"type":"search\_phase\_execution\_exception","reason":"all shards failed","phase":"query","grouped":true,"failed\_shards":[{"shard":0,"index":"staticinfo-2018.11","node":"ucDfjzdORoSIjMKnvthTmw","reason":{"type":"aggregation\_execution\_exception","reason":"Unsupported script value [OFF], expected a number, date, or boolean"}}]},"status":500}}"

Please let me know your thoughts and it would be very helpful.

Regards,  
Ganeshbabu R

---

<div class="post-metadata">

**Author:** ![Brandon\_Kobel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/brandon_kobel/32/14829_2.png) [@Brandon\_Kobel](https://discuss.elastic.co/u/Brandon_Kobel)\
**Post date:** [November 28, 2018, 3:43pm UTC](https://discuss.elastic.co/t/how-to-convert-number-to-string-using-painless-script-and-visualize-it-in-kibana/158575/2 "2018-11-28T15:43:22Z")

</div>

Hey @r.ganeshbabu, thank you for the clear description of the problem that you're experiencing. What version of Kibana/Elasticsearch are you using? I'm trying trouble re-creating the issue that you're seeing.

---

<div class="post-metadata">

**Author:** ![r.ganeshbabu](https://avatars.discourse-cdn.com/v4/letter/r/4da419/32.png) [@r.ganeshbabu](https://discuss.elastic.co/u/r.ganeshbabu)\
**Post date:** [November 29, 2018, 9:15am UTC](https://discuss.elastic.co/t/how-to-convert-number-to-string-using-painless-script-and-visualize-it-in-kibana/158575/3 "2018-11-29T09:15:32Z")

</div>

> [@Brandon\_Kobel](#):
>
> What version of Kibana/Elasticsearch are you using? I'm trying trouble re-creating the issue that you're seeing.

@Brandon_Kobel,

I am using Elasticsearch & Kibana 6.3.2 version and please correct me if I am doing anything wrong.

Regards,  
Ganeshbabu R

---

<div class="post-metadata">

**Author:** ![Brandon\_Kobel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/brandon_kobel/32/14829_2.png) [@Brandon\_Kobel](https://discuss.elastic.co/u/Brandon_Kobel)\
**Post date:** [November 29, 2018, 2:57pm UTC](https://discuss.elastic.co/t/how-to-convert-number-to-string-using-painless-script-and-visualize-it-in-kibana/158575/4 "2018-11-29T14:57:33Z")

</div>

Hey @r.ganeshbabu, can you share your Visualization's metric configuration?

---

<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 27, 2018, 2:57pm UTC](https://discuss.elastic.co/t/how-to-convert-number-to-string-using-painless-script-and-visualize-it-in-kibana/158575/5 "2018-12-27T14:57:40Z")

</div>

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