Error with scriptfield in visualization

Hello, everybody,

i have created a scripted field and whenever i want to visualize it i get an error:

[esaggs] > Request to Elasticsearch failed: {"error":{"root_cause":[{"type":"aggregation_execution_exception","reason":"Unsupported script value [null], expected a number, date, or boolean"}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"uberagent","node":"52tn91DERquwvDXrqkww_w","reason":{"type":"aggregation_execution_exception","reason":"Unsupported script value [null], expected a number, date, or boolean"}}]},"status":500}

The following settings have been set for the Scripted field:

If I understand it correctly, will a string be returned to me? If yes why? I have declared it as number.

What I find funny is that I also created a script field last week and put it into a visualization and it worked. If I try it again today it does not work.

I work with the Kibana version 7.5.2

Thanks for your help in advance.

This error typically occurs when a script throws an exception. I suspect some documents are sparse, i.e. in some cases that field isn't defined.

Does this work?

if (doc.containsKey('ProcCPUTimeMs') {
  return doc['ProcCPUTimeMs'].value / 100.0
}

When I use the code I get the following error message:

{
"root_cause": [
{
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
"org.elasticsearch.index.fielddata.ScriptDocValues$Longs.get(ScriptDocValues.java:121)",
"org.elasticsearch.index.fielddata.ScriptDocValues$Longs.getValue(ScriptDocValues.java:115)",
"return doc['ProcCPUTimeMs'].value / 1000.0\n}",
" ^---- HERE"
],
"script": "if (doc.containsKey('ProcCPUTimeMs')) {\n return doc['ProcCPUTimeMs'].value / 1000.0\n}",
"lang": "painless"
}
],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "query",
"grouped": true,
"failed_shards": [
{
"shard": 0,
"index": "uberagent",
"node": "52tn91DERquwvDXrqkww_w",
"reason": {
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
"org.elasticsearch.index.fielddata.ScriptDocValues$Longs.get(ScriptDocValues.java:121)",
"org.elasticsearch.index.fielddata.ScriptDocValues$Longs.getValue(ScriptDocValues.java:115)",
"return doc['ProcCPUTimeMs'].value / 1000.0\n}",
" ^---- HERE"
],
"script": "if (doc.containsKey('ProcCPUTimeMs')) {\n return doc['ProcCPUTimeMs'].value / 1000.0\n}",
"lang": "painless",
"caused_by": {
"type": "illegal_state_exception",
"reason": "A document doesn't have a value for a field! Use doc[].size()==0 to check if a document is missing a field!"
}
}
}
]
}

As you say, in many documents this field does not exist or it is empty. When I check the field with the following command: if (doc['ProcCPUTimeMs'].size() ==0) return ''"; the script works but I get the above error when I try to visualize the data.

Or do I always have to check in the script if the field ProcCPUTimeMs is present?

Does anyone have a solution or suggestions?

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