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

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,

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

image

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,

: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

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.

@Brandon_Kobel,

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

Regards,
Ganeshbabu R

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

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