# JSON input for heatmap Kibana 5.2.1

**URL:** <https://discuss.elastic.co/t/json-input-for-heatmap-kibana-5-2-1/77491>\
**Category:** Kibana\
**Created:** [March 6, 2017, 11:43am UTC](https://discuss.elastic.co/t/json-input-for-heatmap-kibana-5-2-1/77491 "2017-03-06T11:43:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Akaren](https://avatars.discourse-cdn.com/v4/letter/a/8dc957/32.png) [@Akaren](https://discuss.elastic.co/u/Akaren)\
**Post date:** [March 6, 2017, 11:43am UTC](https://discuss.elastic.co/t/json-input-for-heatmap-kibana-5-2-1/77491/1 "2017-03-06T11:43:36Z")

</div>

I am having filed "\_type" with values 'call-end', 'call-attempt' and more. I want to divide count of 'call-attempt' with count of 'call-end' (failure/success) and display it in heatmap.

Here is my JSON input:

{"script": {  
"lang": "painless",  
"inline": "int totalSuccess = 0; int totalFailure = 0; for (int i = 0; i \< doc['\_type'].length; ++i) { if(doc['\_type'][i] =='call-end') {totalSuccess += 1;} if(doc['\_type'][i] == 'call-attempt'){totalFailure +=1;}} return totalFailure/totalSuccess ;"  
}  
}

If I return only 'totalFailure' or 'totalSuccess' it returns correct number. But if I want to divide it, it shows error - division by zero. But none of the value is zero.  
What is the problem?

 ![](https://us1.discourse-cdn.com/elastic/original/3X/8/8/881dd6ed8eeb87821e08d6c580d4575bcf516e4a.png)

---

<div class="post-metadata">

**Author:** ![tsullivan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tsullivan/32/31077_2.png) [@tsullivan](https://discuss.elastic.co/u/tsullivan)\
**Post date:** [March 9, 2017, 7:25pm UTC](https://discuss.elastic.co/t/json-input-for-heatmap-kibana-5-2-1/77491/2 "2017-03-09T19:25:10Z")

</div>

Hi Akaren,

Can you please show one of the documents so we can see the structure of what the script is working with?

In Dev Tools Console, just run a query such as:

```auto
GET my_index/my_type_search

```

And copy and paste a document that looks useful to help understand what the script is doing.

---

<div class="post-metadata">

**Author:** ![Akaren](https://avatars.discourse-cdn.com/v4/letter/a/8dc957/32.png) [@Akaren](https://discuss.elastic.co/u/Akaren)\
**Post date:** [March 10, 2017, 10:00am UTC](https://discuss.elastic.co/t/json-input-for-heatmap-kibana-5-2-1/77491/3 "2017-03-10T10:00:45Z")

</div>

I don't have search I have this script inside visualization. How can I open it in Dev Tools?  
This is my request. If I use aggregation "count" it ignores my JSON input field. So I use sum on field that is zero.

I have also tried scripted field that has only 1 and 0 and use the aggregation sum on it and just divide the result by for cycle to sum count of another value but it wasn't working either. When I used "\_value" for result it showed nullpointer exception.

{  
"query": {  
"bool": {  
"must": [  
{  
"query\_string": {  
"query": "type:call-attempt",  
"analyze\_wildcard": true  
}  
},  
{  
"range": {  
"@timestamp": {  
"gte": 1488872514925,  
"lte": 1488919868771,  
"format": "epoch\_millis"  
}  
}  
}  
],  
"must\_not": []  
}  
},  
"size": 0,  
"\_source": {  
"excludes": []  
},  
"aggs": {  
"2": {  
"terms": {  
"field": "attrs.dst\_ca\_name.keyword",  
"size": 10,  
"order": {  
"1": "desc"  
}  
},  
"aggs": {  
"1": {  
"sum": {  
"script": {  
"inline": "int totalSuccess = 0; int totalFailure = 0; for (int i = 0; i \< doc['\_type'].length; ++i) { if(doc['\_type'][i] =='call-end') {totalSuccess += 1;} if(doc['\_type'][i] == 'call-attempt'){totalFailure +=1;}} return totalFailure/totalSuccess ;",  
"lang": "painless"  
}  
}  
},  
"3": {  
"terms": {  
"field": "attrs.src\_ca\_name.keyword",  
"size": 5,  
"order": {  
"1": "desc"  
}  
},  
"aggs": {  
"1": {  
"sum": {  
"script": {  
"inline": "int totalSuccess = 0; int totalFailure = 0; for (int i = 0; i \< doc['\_type'].length; ++i) { if(doc['\_type'][i] =='call-end') {totalSuccess += 1;} if(doc['\_type'][i] == 'call-attempt'){totalFailure +=1;}} return totalFailure/totalSuccess ;",  
"lang": "painless"  
}  
}  
}  
}  
}  
}  
}  
}  
}

---

<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 7, 2017, 10:01am UTC](https://discuss.elastic.co/t/json-input-for-heatmap-kibana-5-2-1/77491/4 "2017-04-07T10:01:02Z")

</div>

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