# Painless script error "Unsupported script value"

**URL:** <https://discuss.elastic.co/t/painless-script-error-unsupported-script-value/211087>\
**Category:** Kibana\
**Tags:** painless\
**Created:** [December 9, 2019, 10:08am UTC](https://discuss.elastic.co/t/painless-script-error-unsupported-script-value/211087 "2019-12-09T10:08:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yacine\_Mourchid](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yacine_mourchid/32/58831_2.png) [@Yacine\_Mourchid](https://discuss.elastic.co/u/Yacine_Mourchid)\
**Post date:** [December 9, 2019, 10:08am UTC](https://discuss.elastic.co/t/painless-script-error-unsupported-script-value/211087/1 "2019-12-09T10:08:18Z")

</div>

Hello,

I'm new with kibana, elasticsearch and painles.  
I try to get my real memory usage of my Redhat server.

So I create a scripted field with this painless script :

```
float a; 
float b; 

if (doc['system.memory.actual.used.bytes'].size() == 0) {return '';}
if ((doc['system.memory.actual.used.bytes'].value == 'Deny') || (doc['system.memory.actual.used.bytes'].value == 'denied') || (doc['system.memory.actual.used.bytes'].value == 'denied by ACL') || (doc['system.memory.actual.used.bytes'].value == 'Denied')) { return 'Deny'; }

if (doc['system.memory.total'].size() == 0) {return '';}
if ((doc['system.memory.total'].value == 'Deny') || (doc['system.memory.total'].value == 'denied') || (doc['system.memory.total'].value == 'denied by ACL') || (doc['system.memory.total'].value == 'Denied')) { return 'Deny'; }

a = doc['system.memory.actual.used.bytes'].value / 1024 / 1024;
b = doc['system.memory.total'].value / 1024 / 1024;

return a / b;

```

So, when I try to use it in visualization, here the error I get :

> [esaggs] \> Request to Elasticsearch failed:{"error":{"root\_cause":[{"type":"aggregation\_execution\_exception","reason":"Unsupported script value , expected a number, date, or boolean"}],"type":"search\_phase\_execution\_exception","reason":"all shards failed","phase":"query","grouped":true,"failed\_shards":[{"shard":0,"index":"metricbeat-7.4.2-2019.12.03-000001","node":"AAgahLHeSLGGF-ADwfLLeg","reason":{"type":"aggregation\_execution\_exception","reason":"Unsupported script value , expected a number, date, or boolean"}}]},"status":500}

I understand that the value that expected should be a number, a date or a boolean. So I modify the type of my variables to put a int instead of a float but nothing happen...

Do you know where is my error ?

Thanks.

---

<div class="post-metadata">

**Author:** ![Yacine\_Mourchid](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yacine_mourchid/32/58831_2.png) [@Yacine\_Mourchid](https://discuss.elastic.co/u/Yacine_Mourchid)\
**Post date:** [December 9, 2019, 10:11am UTC](https://discuss.elastic.co/t/painless-script-error-unsupported-script-value/211087/2 "2019-12-09T10:11:55Z")

</div>

Ok I found my problem.

I've a service which return nothing for doc['system.memory.actual.used.bytes'].  
So in my initial script I return an empty value at the line :

`if (doc['system.memory.actual.used.bytes'].size() == 0) {return '';}`

So I changed what I return to put a boolean and now it's works !!

Hope it will help someone here

---

<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 6, 2020, 10:12am UTC](https://discuss.elastic.co/t/painless-script-error-unsupported-script-value/211087/3 "2020-01-06T10:12:00Z")

</div>

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