Hi, I am creating a scripted metric to use it later for a transfrom. I am trying to get the count of the fields with a specific value, but i receive the next error:
{
"error": {
"root_cause": [
{
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
"state.errores.add(doc['TIPO_ERROR.keyword'].value=='Tecnológico' ? 1:0)",
" ^---- HERE"
],
"script": "state.errores.add(doc['TIPO_ERROR.keyword'].value=='Tecnológico' ? 1:0)",
"lang": "painless"
}
],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "query",
"grouped": true,
"failed_shards": [
{
"shard": 0,
"index": "tandem_atm-0000001",
"node": "KAgsKQnWQZGdUnUZN1itEA",
"reason": {
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
"state.errores.add(doc['TIPO_ERROR.keyword'].value=='Tecnológico' ? 1:0)",
" ^---- HERE"
],
"script": "state.errores.add(doc['TIPO_ERROR.keyword'].value=='Tecnológico' ? 1:0)",
"lang": "painless",
"caused_by": {
"type": "null_pointer_exception",
"reason": null
}
}
}
]
},
"status": 400
}
Here is the code that i execute:
POST atm/_search
{
"size": 0,
"aggs":{
"conteo":{
"scripted_metric": {
"init_script": "state.erorres = []",
"map_script": "state.errores.add(doc['TIPO_ERROR.keyword'].value=='Tecnológico' ? 1:0)",
"combine_script": "int conteo = 0; for (e in state.errores) { conteo += e } return conteo",
"reduce_script": "int conteo = 0; for (a in states) { conteo += a } return conteo"
}
}
}
}
I know i can use the filter aggregation to do that but my intention is to create a transform, and transforms dont accept filter aggregation.
Also i create a scripted field with the same script to make tests and it worked, so i dont know why in the scripted metric doesnt work.
Sorry for the gramaticals mistakes, Thank you