Issue while adding scripts in scripting field

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
at Function.Promise.try (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
at Array.map ()
at Function.Promise.map (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)
at 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)
at 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)
at Scope.$apply (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)
at completeRequest (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)

can anyone suggest me a solution

The Script field is expecting a script using painless syntax, not JSON. The only thing you need in that text box is your script: 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
at Function.Promise.try (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
at Array.map ()
at Function.Promise.map (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)
at 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)
at 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)
at Scope.$apply (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)
at completeRequest (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)

please help me out

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

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