# Update/Upsert based on new and old doc values

**URL:** https://discuss.elastic.co/t/update-upsert-based-on-new-and-old-doc-values/231496
**Category:** Elasticsearch
**Created:** [May 7, 2020, 9:16am UTC](https://discuss.elastic.co/t/update-upsert-based-on-new-and-old-doc-values/231496 "2020-05-07T09:16:48Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![mabr3](https://avatars.discourse-cdn.com/v4/letter/m/a183cd/32.png) [@mabr3](https://discuss.elastic.co/u/mabr3)
#### Post date: [May 7, 2020, 9:16am UTC](https://discuss.elastic.co/t/update-upsert-based-on-new-and-old-doc-values/231496/1 "2020-05-07T09:16:48Z")

</div>

Hello,

I'm wondering if there's anyway to update a document based on the comparison of a value on the original version of the doc and on the new version. An example:

Suppose you have document with id:A with field "field1":1. As part of the ingest pipeline, we create a new field, "field2":"started". Now we insert a new document with id:A and "field1":1, nothing should happen since new.field1 == old.field1, but if new.field1 \> old.field1 then we should update field2 to "ongoing".

Also, I would like it to be an upsert, so that we insert when it doesn't exist. Is there any way to do this?

---

<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: [June 4, 2020, 9:16am UTC](https://discuss.elastic.co/t/update-upsert-based-on-new-and-old-doc-values/231496/2 "2020-06-04T09:16:59Z")

</div>

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