# Update document based on another document

**URL:** <https://discuss.elastic.co/t/update-document-based-on-another-document/185524>\
**Category:** Elasticsearch\
**Created:** [June 12, 2019, 10:30pm UTC](https://discuss.elastic.co/t/update-document-based-on-another-document/185524 "2019-06-12T22:30:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![payal](https://avatars.discourse-cdn.com/v4/letter/p/9de053/32.png) [@payal](https://discuss.elastic.co/u/payal)\
**Post date:** [June 12, 2019, 10:30pm UTC](https://discuss.elastic.co/t/update-document-based-on-another-document/185524/1 "2019-06-12T22:30:27Z")

</div>

We have a situation where we want to compute information of the first document based on a second document that comes in later. Is there an easy way/recommended API to accomplish this?

Example:  
Document 1:  
{"id": "xyz", "timestamp": t1}

Document 2:  
{"another\_field": "relates back to document 1 via id, xyz", "timestamp": t2}

Finally, I need to go back and update document 1 as:  
{"id": "xyz", "time\_elapsed": t2-t1, "timestamp": t1}

---

<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:** [July 10, 2019, 10:30pm UTC](https://discuss.elastic.co/t/update-document-based-on-another-document/185524/2 "2019-07-10T22:30:27Z")

</div>

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