# Issue while adding scripts in scripting field

**URL:** <https://discuss.elastic.co/t/issue-while-adding-scripts-in-scripting-field/143527>\
**Category:** Kibana\
**Created:** [August 8, 2018, 1:29pm UTC](https://discuss.elastic.co/t/issue-while-adding-scripts-in-scripting-field/143527 "2018-08-08T13:29:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jibinoosae](https://avatars.discourse-cdn.com/v4/letter/j/858c86/32.png) [@jibinoosae](https://discuss.elastic.co/u/jibinoosae)\
**Post date:** [August 8, 2018, 1:29pm UTC](https://discuss.elastic.co/t/issue-while-adding-scripts-in-scripting-field/143527/1 "2018-08-08T13:29:40Z")

</div>

i have added value in scripting field

attached image shows the details of my scripting field  
but i am getting following error

Error: Request to Elasticsearch failed: {"error":{"root\_cause":[{"type":"script\_exception","reason":"compile error","script\_stack":["{\n "script\_fields": {\n ...","^---- HERE"],"script":"{\n "script\_fields": {\n "test1": {\n "script": "doc['closed\_at'].value - doc['acctstarttime'].value"\n }\n }\n}","lang":"painless"}],"type":"search\_phase\_execution\_exception","reason":"all shards failed","phase":"query","grouped":true,"failed\_shards":[{"shard":0,"index":"incident","node":"t08G8OyDRWGFS7eqGpjjTA","reason":{"type":"script\_exception","reason":"compile error","script\_stack":["{\n "script\_fields": {\n ...","^---- HERE"],"script":"{\n "script\_fields": {\n "test1": {\n "script": "doc['closed\_at'].value - doc['acctstarttime'].value"\n }\n }\n}","lang":"painless","caused\_by":{"type":"illegal\_argument\_exception","reason":"invalid sequence of tokens near ['{'].","caused\_by":{"type":"no\_viable\_alt\_exception","reason":null}}}}]},"status":500}  
at [http://127.0.0.1:5601/bundles/commons.bundle.js:3:947950](http://127.0.0.1:5601/bundles/commons.bundle.js:3:947950)  
at Function.Promise.try ([http://127.0.0.1:5601/bundles/commons.bundle.js:3:824403](http://127.0.0.1:5601/bundles/commons.bundle.js:3:824403))  
at [http://127.0.0.1:5601/bundles/commons.bundle.js:3:823791](http://127.0.0.1:5601/bundles/commons.bundle.js:3:823791)  
at Array.map ()  
at Function.Promise.map ([http://127.0.0.1:5601/bundles/commons.bundle.js:3:823749](http://127.0.0.1:5601/bundles/commons.bundle.js:3:823749))  
at callResponseHandlers ([http://127.0.0.1:5601/bundles/commons.bundle.js:3:947528](http://127.0.0.1:5601/bundles/commons.bundle.js:3:947528))  
at [http://127.0.0.1:5601/bundles/commons.bundle.js:3:936551](http://127.0.0.1:5601/bundles/commons.bundle.js:3:936551)  
at processQueue ([http://127.0.0.1:5601/bundles/vendors.bundle.js:133:134252](http://127.0.0.1:5601/bundles/vendors.bundle.js:133:134252))  
at [http://127.0.0.1:5601/bundles/vendors.bundle.js:133:135201](http://127.0.0.1:5601/bundles/vendors.bundle.js:133:135201)  
at Scope.$digest ([http://127.0.0.1:5601/bundles/vendors.bundle.js:133:146077](http://127.0.0.1:5601/bundles/vendors.bundle.js:133:146077))  
at Scope.$apply ([http://127.0.0.1:5601/bundles/vendors.bundle.js:133:148856](http://127.0.0.1:5601/bundles/vendors.bundle.js:133:148856))  
at done ([http://127.0.0.1:5601/bundles/vendors.bundle.js:133:101124](http://127.0.0.1:5601/bundles/vendors.bundle.js:133:101124))  
at completeRequest ([http://127.0.0.1:5601/bundles/vendors.bundle.js:133:106024](http://127.0.0.1:5601/bundles/vendors.bundle.js:133:106024))  
at XMLHttpRequest.xhr.onload ([http://127.0.0.1:5601/bundles/vendors.bundle.js:133:106783](http://127.0.0.1:5601/bundles/vendors.bundle.js:133:106783))

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/8/6/860e19bac249ca4c2e63109607f582fb6f99432e.png)

can anyone suggest me a solution

---

<div class="post-metadata">

**Author:** ![Catherine\_Liu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/catherine_liu/32/34294_2.png) [@Catherine\_Liu](https://discuss.elastic.co/u/Catherine_Liu)\
**Post date:** [August 8, 2018, 9:21pm UTC](https://discuss.elastic.co/t/issue-while-adding-scripts-in-scripting-field/143527/2 "2018-08-08T21:21:18Z")

</div>

The `Script` field is expecting a script using [painless syntax](https://www.elastic.co/guide/en/elasticsearch/reference/5.4/modules-scripting-painless-syntax.html), not JSON. The only thing you need in that text box is your script: `doc['closed_at'].value - doc['acctstarttime'].value`.

---

<div class="post-metadata">

**Author:** ![jibinoosae](https://avatars.discourse-cdn.com/v4/letter/j/858c86/32.png) [@jibinoosae](https://discuss.elastic.co/u/jibinoosae)\
**Post date:** [August 9, 2018, 7:02am UTC](https://discuss.elastic.co/t/issue-while-adding-scripts-in-scripting-field/143527/3 "2018-08-09T07:02:03Z")

</div>

> [@Catherine\_Liu](#):
>
> `doc['closed_at'].value - doc['acctstarttime'].value` .

Hi i had made changes as below  
doc['closed\_at'].value - doc['sys\_created\_on'].value

but now also there is the following error  
Error: Request to Elasticsearch failed: {"error":{"root\_cause":[{"type":"script\_exception","reason":"runtime error","script\_stack":["doc['closed\_at'].value - doc['sys\_created\_on'].value"," ^---- HERE"],"script":"doc['closed\_at'].value - doc['sys\_created\_on'].value","lang":"painless"}],"type":"search\_phase\_execution\_exception","reason":"all shards failed","phase":"query","grouped":true,"failed\_shards":[{"shard":0,"index":"incident","node":"t08G8OyDRWGFS7eqGpjjTA","reason":{"type":"script\_exception","reason":"runtime error","script\_stack":["doc['closed\_at'].value - doc['sys\_created\_on'].value"," ^---- HERE"],"script":"doc['closed\_at'].value - doc['sys\_created\_on'].value","lang":"painless","caused\_by":{"type":"class\_cast\_exception","reason":"Cannot apply [-] operation to types [org.joda.time.MutableDateTime] and [org.joda.time.MutableDateTime]."}}}]},"status":500}  
at [http://127.0.0.1:5601/bundles/commons.bundle.js:3:947950](http://127.0.0.1:5601/bundles/commons.bundle.js:3:947950)  
at Function.Promise.try ([http://127.0.0.1:5601/bundles/commons.bundle.js:3:824403](http://127.0.0.1:5601/bundles/commons.bundle.js:3:824403))  
at [http://127.0.0.1:5601/bundles/commons.bundle.js:3:823791](http://127.0.0.1:5601/bundles/commons.bundle.js:3:823791)  
at Array.map ()  
at Function.Promise.map ([http://127.0.0.1:5601/bundles/commons.bundle.js:3:823749](http://127.0.0.1:5601/bundles/commons.bundle.js:3:823749))  
at callResponseHandlers ([http://127.0.0.1:5601/bundles/commons.bundle.js:3:947528](http://127.0.0.1:5601/bundles/commons.bundle.js:3:947528))  
at [http://127.0.0.1:5601/bundles/commons.bundle.js:3:936551](http://127.0.0.1:5601/bundles/commons.bundle.js:3:936551)  
at processQueue ([http://127.0.0.1:5601/bundles/vendors.bundle.js:133:134252](http://127.0.0.1:5601/bundles/vendors.bundle.js:133:134252))  
at [http://127.0.0.1:5601/bundles/vendors.bundle.js:133:135201](http://127.0.0.1:5601/bundles/vendors.bundle.js:133:135201)  
at Scope.$digest ([http://127.0.0.1:5601/bundles/vendors.bundle.js:133:146077](http://127.0.0.1:5601/bundles/vendors.bundle.js:133:146077))  
at Scope.$apply ([http://127.0.0.1:5601/bundles/vendors.bundle.js:133:148856](http://127.0.0.1:5601/bundles/vendors.bundle.js:133:148856))  
at done ([http://127.0.0.1:5601/bundles/vendors.bundle.js:133:101124](http://127.0.0.1:5601/bundles/vendors.bundle.js:133:101124))  
at completeRequest ([http://127.0.0.1:5601/bundles/vendors.bundle.js:133:106024](http://127.0.0.1:5601/bundles/vendors.bundle.js:133:106024))  
at XMLHttpRequest.xhr.onload ([http://127.0.0.1:5601/bundles/vendors.bundle.js:133:106783](http://127.0.0.1:5601/bundles/vendors.bundle.js:133:106783))

please help me out

---

<div class="post-metadata">

**Author:** ![jibinoosae](https://avatars.discourse-cdn.com/v4/letter/j/858c86/32.png) [@jibinoosae](https://discuss.elastic.co/u/jibinoosae)\
**Post date:** [August 16, 2018, 5:52am UTC](https://discuss.elastic.co/t/issue-while-adding-scripts-in-scripting-field/143527/4 "2018-08-16T05:52:19Z")

</div>

Can anyone provide an input over the problem i am facing please

---

<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:** [September 13, 2018, 5:52am UTC](https://discuss.elastic.co/t/issue-while-adding-scripts-in-scripting-field/143527/5 "2018-09-13T05:52:22Z")

</div>

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