# Does something like "upsert" exist in ES?

**URL:** <https://discuss.elastic.co/t/does-something-like-upsert-exist-in-es/7954>\
**Category:** Elasticsearch\
**Created:** [June 3, 2012, 11:06am UTC](https://discuss.elastic.co/t/does-something-like-upsert-exist-in-es/7954 "2012-06-03T11:06:26Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mr\_Johnsson](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mr_johnsson/32/2859_2.png) [@Mr\_Johnsson](https://discuss.elastic.co/u/Mr_Johnsson)\
**Post date:** [June 3, 2012, 11:06am UTC](https://discuss.elastic.co/t/does-something-like-upsert-exist-in-es/7954/1 "2012-06-03T11:06:26Z")

</div>

Is it possible to do an insert if the document/data doesn't exist and on exist just update it?  
Exactly as the mongodb upsert feature.  
Ref: [http://www.mongodb.org/display/DOCS/Updating#Updating-{{upserts}](http://www.mongodb.org/display/DOCS/Updating#Updating-%7B%7Bupserts%7D)}

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [June 3, 2012, 11:08am UTC](https://discuss.elastic.co/t/does-something-like-upsert-exist-in-es/7954/2 "2012-06-03T11:08:02Z")

</div>

That's exactly what ES does when you send a document.

Le 3 juin 2012 à 13:06, "Mr.Johnsson" [c.johnsson@wocodi.com](mailto:c.johnsson@wocodi.com) a écrit :

> Is it possible to do an insert if the document/data doesn't exist and on  
> exist just update it?  
> Exactly as the mongodb upsert feature.  
> Ref: [http://www.mongodb.org/display/DOCS/Updating#Updating-{{upserts}](http://www.mongodb.org/display/DOCS/Updating#Updating-%7B%7Bupserts%7D)}
> 
> --  
> View this message in context: [http://elasticsearch-users.115913.n3.nabble.com/Does-something-like-upsert-exist-in-ES-tp4018743.html](http://elasticsearch-users.115913.n3.nabble.com/Does-something-like-upsert-exist-in-ES-tp4018743.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![Mr\_Johnsson](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mr_johnsson/32/2859_2.png) [@Mr\_Johnsson](https://discuss.elastic.co/u/Mr_Johnsson)\
**Post date:** [June 3, 2012, 12:08pm UTC](https://discuss.elastic.co/t/does-something-like-upsert-exist-in-es/7954/3 "2012-06-03T12:08:45Z")

</div>

Is it possible then to increment/change something if it exists and if not it defaults to something else?  
For example..

inserting....  
id : test,  
count : 1

If next insert is 'id: test' it should set the counter to 2 and so on... if test gets deleted next insert should be 1 and then start counting up again. Exactly as mongos upsert. So far i can't figure this one out 🙂

if test already exist i can throw an update and the count works good but if it doesn't exist i get "document missing" so it doesn't create it. This means that i first have to check if 'test' exist in ES from my code then update it if exist or insert new if not.

Or am i missing something here 🙂

---

<div class="post-metadata">

**Author:** ![Benjamin\_Deveze](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/benjamin_deveze/32/1577_2.png) [@Benjamin\_Deveze](https://discuss.elastic.co/u/Benjamin_Deveze)\
**Post date:** [June 3, 2012, 12:56pm UTC](https://discuss.elastic.co/t/does-something-like-upsert-exist-in-es/7954/4 "2012-06-03T12:56:47Z")

</div>

Hey have you considered using \_version?

On Sunday, June 3, 2012, Mr.Johnsson wrote:

> Is it possible then to increment/change something if it exists and if not  
> it  
> defaults to something else?  
> For example..
> 
> inserting....  
> id : test,  
> count : 1
> 
> If next insert is 'id: test' it should set the counter to 2 and so on... if  
> test gets deleted next insert should be 1 and then start counting up again.  
> Exactly as mongos upsert. So far i can't figure this one out 🙂
> 
> if test already exist i can throw an update and the count works good but if  
> it doesn't exist i get "document missing" so it doesn't create it. This  
> means that i first have to check if 'test' exist in ES from my code then  
> update it if exist or insert new if not.
> 
> Or am i missing something here 🙂
> 
> --  
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/Does-something-like-upsert-exist-in-ES-tp4018743p4018745.html](http://elasticsearch-users.115913.n3.nabble.com/Does-something-like-upsert-exist-in-ES-tp4018743p4018745.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

--  
Benjamin DEVEZE

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [June 7, 2012, 11:53pm UTC](https://discuss.elastic.co/t/does-something-like-upsert-exist-in-es/7954/5 "2012-06-07T23:53:49Z")

</div>

The feature make sense, opened an issue:  
[Update API: Allow to upsert, provide a doc and index it if the doc does not exists · Issue #2008 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/2008).

On Sun, Jun 3, 2012 at 2:08 PM, Mr.Johnsson [c.johnsson@wocodi.com](mailto:c.johnsson@wocodi.com) wrote:

> Is it possible then to increment/change something if it exists and if not  
> it  
> defaults to something else?  
> For example..
> 
> inserting....  
> id : test,  
> count : 1
> 
> If next insert is 'id: test' it should set the counter to 2 and so on... if  
> test gets deleted next insert should be 1 and then start counting up again.  
> Exactly as mongos upsert. So far i can't figure this one out 🙂
> 
> if test already exist i can throw an update and the count works good but if  
> it doesn't exist i get "document missing" so it doesn't create it. This  
> means that i first have to check if 'test' exist in ES from my code then  
> update it if exist or insert new if not.
> 
> Or am i missing something here 🙂
> 
> --  
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/Does-something-like-upsert-exist-in-ES-tp4018743p4018745.html](http://elasticsearch-users.115913.n3.nabble.com/Does-something-like-upsert-exist-in-ES-tp4018743p4018745.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<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, 3:25am UTC](https://discuss.elastic.co/t/does-something-like-upsert-exist-in-es/7954/6 "2017-07-06T03:25:16Z")

</div>


