# Upsert if modified

**URL:** <https://discuss.elastic.co/t/upsert-if-modified/16075>\
**Category:** Elasticsearch\
**Created:** [February 28, 2014, 5:20pm UTC](https://discuss.elastic.co/t/upsert-if-modified/16075 "2014-02-28T17:20:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andrew\_Mehler](https://avatars.discourse-cdn.com/v4/letter/a/41988e/32.png) [@Andrew\_Mehler](https://discuss.elastic.co/u/Andrew_Mehler)\
**Post date:** [February 28, 2014, 5:20pm UTC](https://discuss.elastic.co/t/upsert-if-modified/16075/1 "2014-02-28T17:20:11Z")

</div>

Is there a way to instruct the update api to 'upsert if modified' ? From  
what I can tell, a new document will be updated wether or not anything has  
changed.

Say I get a daily snapshot of users and their information from some  
external source. Most days ~85% of the user data will not have changed,  
but there will be some users updating their information, as well as new  
users. I'd prefer sending the entire data set to ES as an 'upsert if  
modified' operation, rather than having to get each document from the  
index, and chcek if there is a difference, and then issuing the update.

Thanks,  
Andrew

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/a7c5d5b4-c15f-46e8-b636-e461b359db77%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/a7c5d5b4-c15f-46e8-b636-e461b359db77%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Binh\_Ly\_2](https://avatars.discourse-cdn.com/v4/letter/b/d07c76/32.png) [@Binh\_Ly\_2](https://discuss.elastic.co/u/Binh_Ly_2)\
**Post date:** [February 28, 2014, 9:20pm UTC](https://discuss.elastic.co/t/upsert-if-modified/16075/2 "2014-02-28T21:20:06Z")

</div>

No there is no such capability. However, there is something that may be of  
interest. When you update/insert, you can pass a version along with it.  
This version can be set to "come from an external source" in which case you  
have complete control over the semantics of the version and how updates  
work. In the case of external version semantics, ES will update a document  
only if your supplied external version is higher than the current version  
of the document. You can generate version numbers yourself and you could  
extract this from say a last\_updated\_timestamp from your external source IF  
you have it. More details about this capability here:

> **[Elasticsearch Versioning Support
	  	 | Elastic](https://www.elastic.co/blog/elasticsearch-versioning-support)**
>
> Elasticsearch Versioning Support One of the key principles behind Elasticsearch is to allow you to make the most out of your data. Historically, search was a read-only enterprise where a search engine...

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/2c9e07f0-ca3d-4977-999f-f120712bf2e5%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/2c9e07f0-ca3d-4977-999f-f120712bf2e5%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Andrew\_Mehler](https://avatars.discourse-cdn.com/v4/letter/a/41988e/32.png) [@Andrew\_Mehler](https://discuss.elastic.co/u/Andrew_Mehler)\
**Post date:** [February 28, 2014, 10:55pm UTC](https://discuss.elastic.co/t/upsert-if-modified/16075/3 "2014-02-28T22:55:26Z")

</div>

Thanks. Unfortunately we have no such field. This may be a useful feature  
to include in ES. Since the update doc is already being merged with the  
existing doc, the isModified could easily be done during the merge.

On Friday, February 28, 2014 12:20:11 PM UTC-5, Andrew Mehler wrote:

> Is there a way to instruct the update api to 'upsert if modified' ? From  
> what I can tell, a new document will be updated wether or not anything has  
> changed.
> 
> Say I get a daily snapshot of users and their information from some  
> external source. Most days ~85% of the user data will not have changed,  
> but there will be some users updating their information, as well as new  
> users. I'd prefer sending the entire data set to ES as an 'upsert if  
> modified' operation, rather than having to get each document from the  
> index, and chcek if there is a difference, and then issuing the update.
> 
> Thanks,  
> Andrew

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/3087f841-087f-4d21-be4f-b8cf737b3cf3%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/3087f841-087f-4d21-be4f-b8cf737b3cf3%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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 6, 2017, 1:46am UTC](https://discuss.elastic.co/t/upsert-if-modified/16075/4 "2017-07-06T01:46:24Z")

</div>


