# Help with bucket\_script in visualize

**URL:** <https://discuss.elastic.co/t/help-with-bucket-script-in-visualize/173517>\
**Category:** Kibana\
**Created:** [March 22, 2019, 3:17pm UTC](https://discuss.elastic.co/t/help-with-bucket-script-in-visualize/173517 "2019-03-22T15:17:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jorjao](https://avatars.discourse-cdn.com/v4/letter/j/7bcc69/32.png) [@jorjao](https://discuss.elastic.co/u/jorjao)\
**Post date:** [March 22, 2019, 3:17pm UTC](https://discuss.elastic.co/t/help-with-bucket-script-in-visualize/173517/1 "2019-03-22T15:17:35Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 19, 2019, 4:28pm UTC](https://discuss.elastic.co/t/help-with-bucket-script-in-visualize/173517/3 "2019-04-19T16:28:32Z")

</div>

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