Help with bucket_script in visualize

I need to create a visualization that per month shows me the percentage of completion of the dates of my tasks.

In my get I constroy 3 aggs: total_tasks where i count total tasks and tarefas_cumpriram_prazo where i count tasks with data_limite_ultrapassada = 0 (tasks ok).
And finally i use bucket_script where "script": "params.noPrazo / params.total * 100"

GET pathfinder_tasks/_search
{
"size": 0,
"aggs" : {
"percentagem_cumprimento" : {
"date_histogram" : {
"field" : "startTime",
"interval" : "month"
},
"aggs": {
"total_tasks": {
"value_count": {
"field": "data_limite_ultrapassada"
}
},
"tarefas_cumpriram_prazo": {
"filter": {
"term": {
"data_limite_ultrapassada": "0"
}
},
"aggs": {
"contagem": {
"value_count": {
"field": "data_limite_ultrapassada"
}
}
}
},
"percentagem":{
"bucket_script": {
"buckets_path": {
"noPrazo": "tarefas_cumpriram_prazo>contagem",
"total": "total_tarefas"
},
"script": "params.noPrazo / params.total * 100"
}
}}}}
}

Example to result:

{
"key_as_string" : "2019-01-01T00:00:00.000Z",
"key" : 1546300800000,
"doc_count" : 1366,
"tarefas_cumpriram_prazo" : {
"doc_count" : 1054,
"contagem" : {
"value" : 1054
}
},
"total_tasks" : {
"value" : 1366
},
"percentagem" : {
"value" : 77.15959004392387
}
},
{
"key_as_string" : "2019-02-01T00:00:00.000Z",
"key" : 1548979200000,
"doc_count" : 1667,
"tarefas_cumpriram_prazo" : {
"doc_count" : 1483,
"contagem" : {
"value" : 1483
}
},
"total_tasks" : {
"value" : 1667
},
"percentagem" : {
"value" : 88.9622075584883
}

Is it possible to do this with Kibana? How to make ? Is possible use bucket_script in goal visualize or or other without being TSVB?

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