# \-(subtraction) of long integer thronging exception in scripted fields in kibana 6.1.2

**URL:** <https://discuss.elastic.co/t/subtraction-of-long-integer-thronging-exception-in-scripted-fields-in-kibana-6-1-2/118600>\
**Category:** Kibana\
**Created:** [February 6, 2018, 10:00am UTC](https://discuss.elastic.co/t/subtraction-of-long-integer-thronging-exception-in-scripted-fields-in-kibana-6-1-2/118600 "2018-02-06T10:00:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bvnages](https://avatars.discourse-cdn.com/v4/letter/b/ecccb3/32.png) [@bvnages](https://discuss.elastic.co/u/bvnages)\
**Post date:** [February 6, 2018, 10:00am UTC](https://discuss.elastic.co/t/subtraction-of-long-integer-thronging-exception-in-scripted-fields-in-kibana-6-1-2/118600/1 "2018-02-06T10:00:10Z")

</div>

Hi All,

I am getting an exception as below. Please help me out.

`Error: Request to Elasticsearch failed: {"error":{"root_cause":[{"type":"script_exception","reason":"runtime error","script_stack":["return (doc['issues.fields.resolutiondate'].value - doc['issues.fields.created'].value)/1000/60/60/24;"," ^---- HERE"],"script":"if(doc['issues.fields.resolutiondate'].value != 0 && doc['issues.fields.created'].value != 0) return (doc['issues.fields.resolutiondate'].value - doc['issues.fields.created'].value)/1000/60/60/24;","lang":"painless"}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"fetch","grouped":true,"failed_shards":[{"shard":0,"index":"jira-db","node":"PyQpy3RDSAu7hMnnEXxGlg","reason":{"type":"script_exception","reason":"runtime error","script_stack":["return (doc['issues.fields.resolutiondate'].value - doc['issues.fields.created'].value)/1000/60/60/24;"," ^---- HERE"],"script":"if(doc['issues.fields.resolutiondate'].value != 0 && doc['issues.fields.created'].value != 0) return (doc['issues.fields.resolutiondate'].value - doc['issues.fields.created'].value)/1000/60/60/24;","lang":"painless","caused_by":{"type":"class_cast_exception","reason":**"Cannot apply [-] operation to types [org.joda.time.DateTime] and [org.joda.time.DateTime]."}}}]},"status":500}**`

I think the reason for the above error.

**"Cannot apply [-] operation to types [org.joda.time.DateTime] and [org.joda.time.DateTime]."}}}]},"status":500}**`

---

<div class="post-metadata">

**Author:** ![thomasneirynck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thomasneirynck/32/23313_2.png) [@thomasneirynck](https://discuss.elastic.co/u/thomasneirynck)\
**Post date:** [February 7, 2018, 6:07pm UTC](https://discuss.elastic.co/t/subtraction-of-long-integer-thronging-exception-in-scripted-fields-in-kibana-6-1-2/118600/2 "2018-02-07T18:07:46Z")

</div>

hi @bvnages,

Instead of working with the value property directly, try getting the timestamp explicitly in your script.

`doc['@timestamp'].value.getMillis();`

There's more info here about using date-functions in Painless here: [https://www.elastic.co/guide/en/elasticsearch/painless/5.5/painless-api-reference.html#painless-api-reference-org-joda-time-ReadableDateTime](https://www.elastic.co/guide/en/elasticsearch/painless/5.5/painless-api-reference.html#painless-api-reference-org-joda-time-ReadableDateTime)

---

<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:** [March 7, 2018, 6:07pm UTC](https://discuss.elastic.co/t/subtraction-of-long-integer-thronging-exception-in-scripted-fields-in-kibana-6-1-2/118600/3 "2018-03-07T18:07:57Z")

</div>

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