# Scripting in Kibana

**URL:** <https://discuss.elastic.co/t/scripting-in-kibana/147948>\
**Category:** Kibana\
**Created:** [September 10, 2018, 11:19am UTC](https://discuss.elastic.co/t/scripting-in-kibana/147948 "2018-09-10T11:19:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![shrikantgulia](https://avatars.discourse-cdn.com/v4/letter/s/c68b51/32.png) [@shrikantgulia](https://discuss.elastic.co/u/shrikantgulia)\
**Post date:** [September 10, 2018, 11:19am UTC](https://discuss.elastic.co/t/scripting-in-kibana/147948/1 "2018-09-10T11:19:06Z")

</div>

I created a scripted field with the name ("indexing\_latency") now i want to use this scripted field in another scripted field which is like  
def x = doc['indexing\_latency'].value;  
if ( x \> 0) {  
def z = 1;  
return z  
}  
else {  
def a = 0;  
return a  
}  
but it is showing an error  
Error with Painless scripted field 'def x = doc['indexing\_latency'].value; if ( x \> 0) { def z = 1; return z } else { def a = 0; return a }'

You can address this error by editing the ‘def x = doc['indexing\_latency'].value; if ( x \> 0) { def z = 1; return z } else { def a = 0; return a }’ field in [Management \> Index Patterns](http://treepye1.smartcirqls.com:5601/app/kibana#/management/kibana/indices), under the “Scripted fields” tab.

```auto
Request to Elasticsearch failed: {"error":{"root_cause":[{"type":"script_exception","reason":"runtime error","script_stack":["org.elasticsearch.search.lookup.LeafDocLookup.get(LeafDocLookup.java:81)","org.elasticsearch.search.lookup.LeafDocLookup.get(LeafDocLookup.java:39)","x = doc['indexing_latency'].value;\n"," ^---- HERE"],"script":"def x = doc['indexing_latency'].value;\nif ( x > 0) {\ndef z = 1;\nreturn z\n}\nelse {\ndef a = 0;\nreturn a\n}","lang":"painless"}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"fetch","grouped":true,"failed_shards":[{"shard":0,"index":"tpy_elk_instances_indexing_metric","node":"OLpIShaoSbaeggOPGnBRxA","reason":{"type":"script_exception","reason":"runtime error","script_stack":["org.elasticsearch.search.lookup.LeafDocLookup.get(LeafDocLookup.java:81)","org.elasticsearch.search.lookup.LeafDocLookup.get(LeafDocLookup.java:39)","x = doc['indexing_latency'].value;\n"," ^---- HERE"],"script":"def x = doc['indexing_latency'].value;\nif ( x > 0) {\ndef z = 1;\nreturn z\n}\nelse {\ndef a = 0;\nreturn a\n}","lang":"painless","caused_by":{"type":"illegal_argument_exception","reason":"No field found for [indexing_latency] in mapping with types []"}}}]},"status":500}

```

after that i also tried this

def x = doc['index\_total'].value;  
def y = doc['index\_time\_in\_millis'].value;  
{  
if ( x \> 0) {  
def z = y / x;  
return z  
}  
else {  
def z = 5 \* 0;  
return z  
}  
}  
if ( z \> 0) {  
def l = 0;  
return l  
}  
else {  
def f = 1;  
return f  
}  
by creating the "indexing\_latency" field and using it in the in loop but this is also throwing an error.

A help would be really appreciated

Best Regards  
Shrikant

---

<div class="post-metadata">

**Author:** ![Joe\_Fleming](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joe_fleming/32/3561_2.png) [@Joe\_Fleming](https://discuss.elastic.co/u/Joe_Fleming)\
**Post date:** [September 10, 2018, 10:33pm UTC](https://discuss.elastic.co/t/scripting-in-kibana/147948/2 "2018-09-10T22:33:34Z")

</div>

> i want to use this scripted field in another scripted field

Unfortunately, Kibana can't do this. Scripted fields in Kibana are a kind of "virtual field" which are created at query time using the stored script. Because it's not a real field, it can't be reused like that in another script.

---

<div class="post-metadata">

**Author:** ![shrikantgulia](https://avatars.discourse-cdn.com/v4/letter/s/c68b51/32.png) [@shrikantgulia](https://discuss.elastic.co/u/shrikantgulia)\
**Post date:** [September 11, 2018, 1:13am UTC](https://discuss.elastic.co/t/scripting-in-kibana/147948/3 "2018-09-11T01:13:49Z")

</div>

@Joe_Fleming  
Thankyou for the response  
Any other way to use this field.  
A help would be really appreciated

Regards  
Shrikant

---

<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:** [October 9, 2018, 1:25am UTC](https://discuss.elastic.co/t/scripting-in-kibana/147948/4 "2018-10-09T01:25:00Z")

</div>

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