# Updating document with scripted\_metric aggregation result

**URL:** <https://discuss.elastic.co/t/updating-document-with-scripted-metric-aggregation-result/76011>\
**Category:** Elasticsearch\
**Created:** [February 22, 2017, 10:01am UTC](https://discuss.elastic.co/t/updating-document-with-scripted-metric-aggregation-result/76011 "2017-02-22T10:01:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![elk\_user1](https://avatars.discourse-cdn.com/v4/letter/e/a698b9/32.png) [@elk\_user1](https://discuss.elastic.co/u/elk_user1)\
**Post date:** [February 22, 2017, 10:01am UTC](https://discuss.elastic.co/t/updating-document-with-scripted-metric-aggregation-result/76011/1 "2017-02-22T10:01:35Z")

</div>

Hi there,

I have a scripted metric which computes timestamp difference between start and end events [two documents in an index]. Is there any way to update the end event document with the computed time?

Eg,  
{name: 'Device2', type: 'start', 'eventTime': '2013-02-19 12:00:00'}  
{name: 'Device1', type: 'end', 'eventTime': '2013-02-19 13:00:00'}

I want to update the second document (add aggregated result) as,  
{name: 'Device1', type: 'end', 'eventTime': '2013-02-19 13:00:00', 'timeOnEvent':60}

Thanks,  
Deepti

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [February 27, 2017, 9:27am UTC](https://discuss.elastic.co/t/updating-document-with-scripted-metric-aggregation-result/76011/2 "2017-02-27T09:27:25Z")

</div>

Hey,

you need to do this in your application on the client side when you receive the result back.

--Alex

---

<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 27, 2017, 9:27am UTC](https://discuss.elastic.co/t/updating-document-with-scripted-metric-aggregation-result/76011/3 "2017-03-27T09:27:35Z")

</div>

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