Painless script error "Unsupported script value"


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[''].size() == 0) {return '';}
if ((doc[''].value == 'Deny') || (doc[''].value == 'denied') || (doc[''].value == 'denied by ACL') || (doc[''].value == 'Denied')) { return 'Deny'; }

a = doc['system.memory.actual.used.bytes'].value / 1024 / 1024;
b = doc[''].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 ?


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

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