# How doc\_as\_upsert works

**URL:** https://discuss.elastic.co/t/how-doc-as-upsert-works/89240
**Category:** Elasticsearch
**Created:** [June 13, 2017, 4:31pm UTC](https://discuss.elastic.co/t/how-doc-as-upsert-works/89240 "2017-06-13T16:31:14Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![mohigup](https://avatars.discourse-cdn.com/v4/letter/m/f08c70/32.png) [@mohigup](https://discuss.elastic.co/u/mohigup)
#### Post date: [June 13, 2017, 4:31pm UTC](https://discuss.elastic.co/t/how-doc-as-upsert-works/89240/1 "2017-06-13T16:31:14Z")

</div>

I tried creating document (id=1) using **PUT** to **/\_update** with " **doc\_as\_upsert**" : true and doc field. The response " **result**" attribute had value " **created**" and " **version**" attribute had value " **1**".

Again, I updated the same document with all attributes as before (id=1) using **PUT** to **/\_update** with " **doc\_as\_upsert**" : **true** and **doc** field. The response " **result**" attribute had value " **noop**" and " **version**" attribute had value " **1**".

Now, I updated the same document with all attributes but one changed (id=1) using **PUT** to **/\_update** with " **doc\_as\_upsert**" : true and **doc** field. The response " **result**" attribute had value " **updated**" and " **version**" attribute had value " **2**".

As far I understand, EL checks each attribute of the document in input against the document in index and returns response based on following:

**case 1:** If there is no match, it returns "noop"  
**case 2:** If there is at least one difference, it returns "updated"  
**case 3:** if the document doesn't exists, it creates a new document and returns "created"

How does EL handles the above behaviour? Is there any hashing performed to determine changes?  
Can someone confirm that no indexing happens for case 1?

---

<div class="post-metadata">

### Author: ![Dan\_Markhasin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dan_markhasin/32/14187_2.png) [@Dan\_Markhasin](https://discuss.elastic.co/u/Dan_Markhasin)
#### Post date: [June 13, 2017, 8:06pm UTC](https://discuss.elastic.co/t/how-doc-as-upsert-works/89240/2 "2017-06-13T20:06:14Z")

</div>

> **[Update API | Elasticsearch Guide \[8.11\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update.html#_detecting_noop_updates)**

> By default updates that don’t change anything detect that they don’t change anything and return "result": "noop"

---

<div class="post-metadata">

### Author: ![mohigup](https://avatars.discourse-cdn.com/v4/letter/m/f08c70/32.png) [@mohigup](https://discuss.elastic.co/u/mohigup)
#### Post date: [June 13, 2017, 11:07pm UTC](https://discuss.elastic.co/t/how-doc-as-upsert-works/89240/3 "2017-06-13T23:07:24Z")

</div>

Hi Dan,

Thanks for the Reply. However, I am looking for the internal logic that is used to detect changes and if someone can confirm that there is no indexing happens for case 1.

---

<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 11, 2017, 11:07pm UTC](https://discuss.elastic.co/t/how-doc-as-upsert-works/89240/4 "2017-07-11T23:07:57Z")

</div>

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