# I wanted to write code inside scripted\_fields in kibana

**URL:** <https://discuss.elastic.co/t/i-wanted-to-write-code-inside-scripted-fields-in-kibana/174795>\
**Category:** Kibana\
**Created:** [April 1, 2019, 1:37pm UTC](https://discuss.elastic.co/t/i-wanted-to-write-code-inside-scripted-fields-in-kibana/174795 "2019-04-01T13:37:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shubhangi\_Priya](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shubhangi_priya/32/43222_2.png) [@Shubhangi\_Priya](https://discuss.elastic.co/u/Shubhangi_Priya)\
**Post date:** [April 1, 2019, 1:37pm UTC](https://discuss.elastic.co/t/i-wanted-to-write-code-inside-scripted-fields-in-kibana/174795/1 "2019-04-01T13:37:31Z")

</div>

I wanted to have a ratio of sum of the document when its suggestion is auto (doc['driverSuggestion'].value== 'AUTO') to divide it by sum of the document when its suggestion is auto plus manual. sum(doc['driverSuggestion'].value== 'AUTO')/(sum(doc['driverSuggestion'].value== 'AUTO')+sum(doc['driverSuggestion'].value== 'MANUAL'))

How to do it?

---

<div class="post-metadata">

**Author:** ![nickpeihl](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nickpeihl/32/112622_2.png) [@nickpeihl](https://discuss.elastic.co/u/nickpeihl)\
**Post date:** [April 1, 2019, 11:54pm UTC](https://discuss.elastic.co/t/i-wanted-to-write-code-inside-scripted-fields-in-kibana/174795/2 "2019-04-01T23:54:40Z")

</div>

Can you provide an example document? I do not really understand what numbers are trying to sum.

---

<div class="post-metadata">

**Author:** ![Shubhangi\_Priya](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shubhangi_priya/32/43222_2.png) [@Shubhangi\_Priya](https://discuss.elastic.co/u/Shubhangi_Priya)\
**Post date:** [April 2, 2019, 4:58am UTC](https://discuss.elastic.co/t/i-wanted-to-write-code-inside-scripted-fields-in-kibana/174795/3 "2019-04-02T04:58:10Z")

</div>

{  
"driverSuggestion": "MANUAL",  
"expiryDriverIds": [  
"only1curtis5@gmail.com",  
"pdburbanks5@gmail.com"]  
}

---

<div class="post-metadata">

**Author:** ![nickpeihl](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nickpeihl/32/112622_2.png) [@nickpeihl](https://discuss.elastic.co/u/nickpeihl)\
**Post date:** [April 2, 2019, 10:36pm UTC](https://discuss.elastic.co/t/i-wanted-to-write-code-inside-scripted-fields-in-kibana/174795/4 "2019-04-02T22:36:15Z")

</div>

I don't see anything that can be summed in this document. Are you trying to count the items in the `expiryDriverIds` array?

---

<div class="post-metadata">

**Author:** ![Shubhangi\_Priya](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shubhangi_priya/32/43222_2.png) [@Shubhangi\_Priya](https://discuss.elastic.co/u/Shubhangi_Priya)\
**Post date:** [April 3, 2019, 11:18am UTC](https://discuss.elastic.co/t/i-wanted-to-write-code-inside-scripted-fields-in-kibana/174795/5 "2019-04-03T11:18:59Z")

</div>

> [@There has been some discrepancies in the data in timelion graph](https://discuss.elastic.co/t/there-has-been-some-discrepancies-in-the-data-in-timelion-graph/174968):
>
> I am adding the document in the es , I am able to see the document in discover mode. But the same data is not reflecting when I am seeing it in timelion graph. Suppose the data of 2014 year has been added present in discover mode and not reflecting in timelion graph. Can some one tell why its happening?

previous issue got resolved can you help with this one?

---

<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:** [May 1, 2019, 11:19am UTC](https://discuss.elastic.co/t/i-wanted-to-write-code-inside-scripted-fields-in-kibana/174795/6 "2019-05-01T11:19:09Z")

</div>

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