# Scripted Fields in kibana not working

**URL:** <https://discuss.elastic.co/t/scripted-fields-in-kibana-not-working/117661>\
**Category:** Kibana\
**Created:** [January 30, 2018, 4:30pm UTC](https://discuss.elastic.co/t/scripted-fields-in-kibana-not-working/117661 "2018-01-30T16:30:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![cilzzz](https://avatars.discourse-cdn.com/v4/letter/c/c67d28/32.png) [@cilzzz](https://discuss.elastic.co/u/cilzzz)\
**Post date:** [January 30, 2018, 4:30pm UTC](https://discuss.elastic.co/t/scripted-fields-in-kibana-not-working/117661/1 "2018-01-30T16:30:20Z")

</div>

Scripted fields only calculate sum,length and count by line ,not the entire document this is my script below:

def sum = 0;  
for (def i = 0; i \< doc['Return\_Code'].length; i++) {  
sum = sum +doc['Return\_Code'][i];  
}  
return sum;

and this the result:

 ![Capture](https://us1.discourse-cdn.com/elastic/original/3X/a/b/aba34e17ed5f2ceec1528e2521af48f196482fe5.PNG)

I need to get 7 as values in the somme field so i can calculate the success rate 7/10=0.7 and show it in a metric any help please.

thank you!

---

<div class="post-metadata">

**Author:** ![tylersmalley](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tylersmalley/32/8833_2.png) [@tylersmalley](https://discuss.elastic.co/u/tylersmalley)\
**Post date:** [January 31, 2018, 1:17am UTC](https://discuss.elastic.co/t/scripted-fields-in-kibana-not-working/117661/2 "2018-01-31T01:17:50Z")

</div>

It's possible to do this with the Time Series Visual Builder

I have used the following data to test against:

```auto
POST discuss-117661/doc
{
  "@timestamp": "2018-01-30T14:25:04",
  "Return_Code": 1,
  "somme": 1
}

POST discuss-117661/doc
{
  "@timestamp": "2018-01-30T14:25:04",
  "Return_Code": 1,
  "somme": 1
}

POST discuss-117661/doc
{
  "@timestamp": "2018-01-30T14:25:04",
  "Return_Code": 1,
  "somme": 1
}

POST discuss-117661/doc
{
  "@timestamp": "2018-01-30T14:25:04",
  "Return_Code": 0,
  "somme": 0
}

POST discuss-117661/doc
{
  "@timestamp": "2018-01-30T14:25:04",
  "Return_Code": 0,
  "somme": 0
}

POST discuss-117661/doc
{
  "@timestamp": "2018-01-30T14:25:04",
  "Return_Code": 0,
  "somme": 0
}

POST discuss-117661/doc
{
  "@timestamp": "2018-01-30T14:25:04",
  "Return_Code": 1,
  "somme": 1
}

POST discuss-117661/doc
{
  "@timestamp": "2018-01-30T14:25:04",
  "Return_Code": 1,
  "somme": 1
}

POST discuss-117661/doc
{
  "@timestamp": "2018-01-30T14:25:04",
  "Return_Code": 1,
  "somme": 1
}

POST discuss-117661/doc
{
  "@timestamp": "2018-01-30T14:25:04",
  "Return_Code": 1,
  "somme": 1
}

```

Create a new visualization using the Time Series Visual Builder.

First, select the Panel Options tab and enter the index pattern you would want to use.

Then, back on the Data tab, select use the Filter Ratio Aggregation. For the numerator, we will select the successful documents using `Return_Code:1`

 ![11](https://us1.discourse-cdn.com/elastic/original/3X/0/a/0ad79106eeb0faca52a8fa2a304d37065b544fd6.png)

---

<div class="post-metadata">

**Author:** ![cilzzz](https://avatars.discourse-cdn.com/v4/letter/c/c67d28/32.png) [@cilzzz](https://discuss.elastic.co/u/cilzzz)\
**Post date:** [January 31, 2018, 8:52am UTC](https://discuss.elastic.co/t/scripted-fields-in-kibana-not-working/117661/3 "2018-01-31T08:52:16Z")

</div>

thank you but it is showing 0 i don't know why , is there a way to do it and visualize it through scripted field ?

---

<div class="post-metadata">

**Author:** ![tylersmalley](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tylersmalley/32/8833_2.png) [@tylersmalley](https://discuss.elastic.co/u/tylersmalley)\
**Post date:** [January 31, 2018, 6:37pm UTC](https://discuss.elastic.co/t/scripted-fields-in-kibana-not-working/117661/4 "2018-01-31T18:37:32Z")

</div>

This is not possible with scripted fields. A scripted field is just that, a dynamic field on the document. It has no knowledge of other documents.

---

<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:** [February 28, 2018, 6:37pm UTC](https://discuss.elastic.co/t/scripted-fields-in-kibana-not-working/117661/5 "2018-02-28T18:37:42Z")

</div>

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