# Checking update results

**URL:** <https://discuss.elastic.co/t/checking-update-results/20019>\
**Category:** Elasticsearch\
**Created:** [October 1, 2014, 9:21am UTC](https://discuss.elastic.co/t/checking-update-results/20019 "2014-10-01T09:21:15Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aviv\_Eyal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aviv_eyal/32/1244_2.png) [@Aviv\_Eyal](https://discuss.elastic.co/u/Aviv_Eyal)\
**Post date:** [October 1, 2014, 9:21am UTC](https://discuss.elastic.co/t/checking-update-results/20019/1 "2014-10-01T09:21:15Z")

</div>

Hi, I'm new to elasticsearch so there might be an obvious answer to this  
question.

What's the best way to check the status of an update operation that changed  
the value of an existing property?  
I'm using a doc to update an existing indexed document using the java  
update api:

UpdateResponse updateResponse = client.prepareUpdate("content",  
"contentitem", item.id)  
.setDoc(xb).execute().actionGet();

updateResponse.isCreated() only returns true if the doc was inserted using  
an upsert operation and updateResponse.getGetResult() returns null null.

I've looked in the ES tests source code and the way the test is performed  
there is by issuing a new get request for the updated fields and comparing  
the values from ES with the values set in the update:

// change existing field  
updateResponse = client().prepareUpdate(indexOrAlias(), "type1",  
"1").setDoc(XContentFactory.jsonBuilder().startObject().field("field",  
3).endObject()).execute().actionGet();  
for (int i = 0; i \< 5; i++) {  
getResponse = client().prepareGet("test", "type1",  
"1").execute().actionGet();

assertThat(getResponse.getSourceAsMap().get("field").toString(),  
equalTo("3"));

assertThat(getResponse.getSourceAsMap().get("field2").toString(),  
equalTo("2"));  
}

I'm curious if this can be done just by using UpdateResponse and without  
using another get.

Thanks!

--  
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/5f9c7a26-fba0-44d4-8f8c-401ac5c4e5e2%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/5f9c7a26-fba0-44d4-8f8c-401ac5c4e5e2%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)\
**Post date:** [October 1, 2014, 11:45am UTC](https://discuss.elastic.co/t/checking-update-results/20019/2 "2014-10-01T11:45:36Z")

</div>

You must issue a new get request after the write. The reason is that update  
works like a write but with a previous get (not with a get after the  
write).

If data is written, the write action is asynchronously executed, the  
previous doc versions become obsolete, and eventually the action has to be  
forwarded to other nodes where the shard(s) for this doc live.

Only when issuing a new get request, ES can route this read request again  
to the primary shard node and open a new reader for this doc. Using the  
"near real-time" (NRT) feature, ES ensures the last version of the doc from  
the cache ca be taken, even if it is not flushed to the index.

Jörg

On Wed, Oct 1, 2014 at 11:21 AM, Aviv Eyal [aviveyal07@gmail.com](mailto:aviveyal07@gmail.com) wrote:

> Hi, I'm new to elasticsearch so there might be an obvious answer to this  
> question.
> 
> What's the best way to check the status of an update operation that  
> changed the value of an existing property?  
> I'm using a doc to update an existing indexed document using the java  
> update api:
> 
> UpdateResponse updateResponse = client.prepareUpdate("content",  
> "contentitem", item.id)  
> .setDoc(xb).execute().actionGet();
> 
> updateResponse.isCreated() only returns true if the doc was inserted using  
> an upsert operation and updateResponse.getGetResult() returns null null.
> 
> I've looked in the ES tests source code and the way the test is performed  
> there is by issuing a new get request for the updated fields and comparing  
> the values from ES with the values set in the update:
> 
> // change existing field  
> updateResponse = client().prepareUpdate(indexOrAlias(), "type1",  
> "1").setDoc(XContentFactory.jsonBuilder().startObject().field("field",  
> 3).endObject()).execute().actionGet();  
> for (int i = 0; i \< 5; i++) {  
> getResponse = client().prepareGet("test", "type1",  
> "1").execute().actionGet();
> 
> assertThat(getResponse.getSourceAsMap().get("field").toString(),  
> equalTo("3"));
> 
> assertThat(getResponse.getSourceAsMap().get("field2").toString(),  
> equalTo("2"));  
> }
> 
> I'm curious if this can be done just by using UpdateResponse and without  
> using another get.
> 
> Thanks!
> 
> --  
> 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/5f9c7a26-fba0-44d4-8f8c-401ac5c4e5e2%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/5f9c7a26-fba0-44d4-8f8c-401ac5c4e5e2%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/5f9c7a26-fba0-44d4-8f8c-401ac5c4e5e2%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/5f9c7a26-fba0-44d4-8f8c-401ac5c4e5e2%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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/CAKdsXoGYsXUbwUjn3Pp64Brip64Xhrp6MQGq1eALrTFu-g8aZg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAKdsXoGYsXUbwUjn3Pp64Brip64Xhrp6MQGq1eALrTFu-g8aZg%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Aviv\_Eyal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aviv_eyal/32/1244_2.png) [@Aviv\_Eyal](https://discuss.elastic.co/u/Aviv_Eyal)\
**Post date:** [October 1, 2014, 11:59am UTC](https://discuss.elastic.co/t/checking-update-results/20019/3 "2014-10-01T11:59:11Z")

</div>

Jörg - thanks for the thoughtful reply. Rephrasing my question a bit: how  
can the code be sure that an update request was at least submitted to ES  
without an error? Surely, an update request may fail due to various runtime  
issues.

On Wednesday, October 1, 2014 12:21:15 PM UTC+3, Aviv Eyal wrote:

> Hi, I'm new to elasticsearch so there might be an obvious answer to this  
> question.
> 
> What's the best way to check the status of an update operation that  
> changed the value of an existing property?  
> I'm using a doc to update an existing indexed document using the java  
> update api:
> 
> UpdateResponse updateResponse = client.prepareUpdate("content",  
> "contentitem", item.id)  
> .setDoc(xb).execute().actionGet();
> 
> updateResponse.isCreated() only returns true if the doc was inserted using  
> an upsert operation and updateResponse.getGetResult() returns null null.
> 
> I've looked in the ES tests source code and the way the test is performed  
> there is by issuing a new get request for the updated fields and comparing  
> the values from ES with the values set in the update:
> 
> // change existing field  
> updateResponse = client().prepareUpdate(indexOrAlias(), "type1",  
> "1").setDoc(XContentFactory.jsonBuilder().startObject().field("field",  
> 3).endObject()).execute().actionGet();  
> for (int i = 0; i \< 5; i++) {  
> getResponse = client().prepareGet("test", "type1",  
> "1").execute().actionGet();
> 
> assertThat(getResponse.getSourceAsMap().get("field").toString(),  
> equalTo("3"));
> 
> assertThat(getResponse.getSourceAsMap().get("field2").toString(),  
> equalTo("2"));  
> }
> 
> I'm curious if this can be done just by using UpdateResponse and without  
> using another get.
> 
> Thanks!

--  
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/bcec4757-542a-4a28-b94c-71fb23d129b3%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/bcec4757-542a-4a28-b94c-71fb23d129b3%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Itamar\_Syn\_Hershko](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/itamar_syn_hershko/32/725_2.png) [@Itamar\_Syn\_Hershko](https://discuss.elastic.co/u/Itamar_Syn_Hershko)\
**Post date:** [October 1, 2014, 12:00pm UTC](https://discuss.elastic.co/t/checking-update-results/20019/4 "2014-10-01T12:00:55Z")

</div>

HTTP status codes are used to communicate errors, for example a runtime  
error would return HTTP status 500

--

Itamar Syn-Hershko  
[http://code972.com](http://code972.com) | @synhershko [https://twitter.com/synhershko](https://twitter.com/synhershko)  
Freelance Developer & Consultant  
Author of RavenDB in Action [http://manning.com/synhershko/](http://manning.com/synhershko/)

On Wed, Oct 1, 2014 at 2:59 PM, Aviv Eyal [aviveyal07@gmail.com](mailto:aviveyal07@gmail.com) wrote:

> Jörg - thanks for the thoughtful reply. Rephrasing my question a bit: how  
> can the code be sure that an update request was at least submitted to ES  
> without an error? Surely, an update request may fail due to various runtime  
> issues.
> 
> On Wednesday, October 1, 2014 12:21:15 PM UTC+3, Aviv Eyal wrote:
> 
> > Hi, I'm new to elasticsearch so there might be an obvious answer to this  
> > question.
> > 
> > What's the best way to check the status of an update operation that  
> > changed the value of an existing property?  
> > I'm using a doc to update an existing indexed document using the java  
> > update api:
> > 
> > UpdateResponse updateResponse = client.prepareUpdate("content",  
> > "contentitem", item.id)  
> > .setDoc(xb).execute().actionGet();
> > 
> > updateResponse.isCreated() only returns true if the doc was inserted  
> > using an upsert operation and updateResponse.getGetResult() returns null  
> > null.
> > 
> > I've looked in the ES tests source code and the way the test is performed  
> > there is by issuing a new get request for the updated fields and comparing  
> > the values from ES with the values set in the update:
> > 
> > // change existing field  
> > updateResponse = client().prepareUpdate(indexOrAlias(), "type1",  
> > "1").setDoc(XContentFactory.jsonBuilder().startObject().field("field",  
> > 3).endObject()).execute().actionGet();  
> > for (int i = 0; i \< 5; i++) {  
> > getResponse = client().prepareGet("test", "type1",  
> > "1").execute().actionGet();  
> > assertThat(getResponse.getSourceAsMap().get("field").toString(),  
> > equalTo("3"));  
> > assertThat(getResponse.getSourceAsMap().get("field2").toString(),  
> > equalTo("2"));  
> > }
> > 
> > I'm curious if this can be done just by using UpdateResponse and without  
> > using another get.
> > 
> > Thanks!
> > 
> > --  
> > 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/bcec4757-542a-4a28-b94c-71fb23d129b3%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/bcec4757-542a-4a28-b94c-71fb23d129b3%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/bcec4757-542a-4a28-b94c-71fb23d129b3%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/bcec4757-542a-4a28-b94c-71fb23d129b3%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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/CAHTr4ZtM%2BSwV%3DquiPH8ochWZoO5nyyg-4FOexcToA%3D46aRrv8w%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAHTr4ZtM%2BSwV%3DquiPH8ochWZoO5nyyg-4FOexcToA%3D46aRrv8w%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Aviv\_Eyal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aviv_eyal/32/1244_2.png) [@Aviv\_Eyal](https://discuss.elastic.co/u/Aviv_Eyal)\
**Post date:** [October 1, 2014, 4:19pm UTC](https://discuss.elastic.co/t/checking-update-results/20019/5 "2014-10-01T16:19:25Z")

</div>

Itamar, I'm using the Java driver and was hoping that UpdateResponse will  
have some kind of status but looks like it doesn't.

On Wednesday, October 1, 2014 3:01:02 PM UTC+3, Itamar Syn-Hershko wrote:

> HTTP status codes are used to communicate errors, for example a runtime  
> error would return HTTP status 500
> 
> --
> 
> Itamar Syn-Hershko  
> [http://code972.com](http://code972.com) | @synhershko [https://twitter.com/synhershko](https://twitter.com/synhershko)  
> Freelance Developer & Consultant  
> Author of RavenDB in Action [http://manning.com/synhershko/](http://manning.com/synhershko/)
> 
> On Wed, Oct 1, 2014 at 2:59 PM, Aviv Eyal \<[avive...@gmail.com](mailto:avive...@gmail.com)  
> \<javascript:\>\> wrote:
> 
> > Jörg - thanks for the thoughtful reply. Rephrasing my question a bit: how  
> > can the code be sure that an update request was at least submitted to ES  
> > without an error? Surely, an update request may fail due to various runtime  
> > issues.
> > 
> > On Wednesday, October 1, 2014 12:21:15 PM UTC+3, Aviv Eyal wrote:
> > 
> > > Hi, I'm new to elasticsearch so there might be an obvious answer to this  
> > > question.
> > > 
> > > What's the best way to check the status of an update operation that  
> > > changed the value of an existing property?  
> > > I'm using a doc to update an existing indexed document using the java  
> > > update api:
> > > 
> > > UpdateResponse updateResponse = client.prepareUpdate("content",  
> > > "contentitem", item.id)  
> > > .setDoc(xb).execute().actionGet();
> > > 
> > > updateResponse.isCreated() only returns true if the doc was inserted  
> > > using an upsert operation and updateResponse.getGetResult() returns  
> > > null null.
> > > 
> > > I've looked in the ES tests source code and the way the test is  
> > > performed there is by issuing a new get request for the updated fields and  
> > > comparing the values from ES with the values set in the update:
> > > 
> > > // change existing field  
> > > updateResponse = client().prepareUpdate(indexOrAlias(),  
> > > "type1", "1").setDoc(XContentFactory.jsonBuilder().startObject().field("field",  
> > > 3).endObject()).execute().actionGet();  
> > > for (int i = 0; i \< 5; i++) {  
> > > getResponse = client().prepareGet("test", "type1",  
> > > "1").execute().actionGet();  
> > > assertThat(getResponse.getSourceAsMap().get("field").toString(),  
> > > equalTo("3"));  
> > > assertThat(getResponse.getSourceAsMap().get("field2").toString(),  
> > > equalTo("2"));  
> > > }
> > > 
> > > I'm curious if this can be done just by using UpdateResponse and without  
> > > using another get.
> > > 
> > > Thanks!
> > > 
> > > --  
> > > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > > To view this discussion on the web visit  
> > > [https://groups.google.com/d/msgid/elasticsearch/bcec4757-542a-4a28-b94c-71fb23d129b3%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/bcec4757-542a-4a28-b94c-71fb23d129b3%40googlegroups.com)  
> > > [https://groups.google.com/d/msgid/elasticsearch/bcec4757-542a-4a28-b94c-71fb23d129b3%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/bcec4757-542a-4a28-b94c-71fb23d129b3%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > .  
> > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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/666ecbbd-8119-42e8-b04e-98b69d0d437c%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/666ecbbd-8119-42e8-b04e-98b69d0d437c%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)\
**Post date:** [October 1, 2014, 4:53pm UTC](https://discuss.elastic.co/t/checking-update-results/20019/6 "2014-10-01T16:53:17Z")

</div>

If you get an UpdateResponse from actionGet(), you can be sure ES has  
executed the action. Otherwise you will get an exception.

Jörg

On Wed, Oct 1, 2014 at 1:59 PM, Aviv Eyal [aviveyal07@gmail.com](mailto:aviveyal07@gmail.com) wrote:

> Jörg - thanks for the thoughtful reply. Rephrasing my question a bit: how  
> can the code be sure that an update request was at least submitted to ES  
> without an error? Surely, an update request may fail due to various runtime  
> issues.
> 
> On Wednesday, October 1, 2014 12:21:15 PM UTC+3, Aviv Eyal wrote:
> 
> > Hi, I'm new to elasticsearch so there might be an obvious answer to this  
> > question.
> > 
> > What's the best way to check the status of an update operation that  
> > changed the value of an existing property?  
> > I'm using a doc to update an existing indexed document using the java  
> > update api:
> > 
> > UpdateResponse updateResponse = client.prepareUpdate("content",  
> > "contentitem", item.id)  
> > .setDoc(xb).execute().actionGet();
> > 
> > updateResponse.isCreated() only returns true if the doc was inserted  
> > using an upsert operation and updateResponse.getGetResult() returns null  
> > null.
> > 
> > I've looked in the ES tests source code and the way the test is performed  
> > there is by issuing a new get request for the updated fields and comparing  
> > the values from ES with the values set in the update:
> > 
> > // change existing field  
> > updateResponse = client().prepareUpdate(indexOrAlias(), "type1",  
> > "1").setDoc(XContentFactory.jsonBuilder().startObject().field("field",  
> > 3).endObject()).execute().actionGet();  
> > for (int i = 0; i \< 5; i++) {  
> > getResponse = client().prepareGet("test", "type1",  
> > "1").execute().actionGet();  
> > assertThat(getResponse.getSourceAsMap().get("field").toString(),  
> > equalTo("3"));  
> > assertThat(getResponse.getSourceAsMap().get("field2").toString(),  
> > equalTo("2"));  
> > }
> > 
> > I'm curious if this can be done just by using UpdateResponse and without  
> > using another get.
> > 
> > Thanks!
> > 
> > --  
> > 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/bcec4757-542a-4a28-b94c-71fb23d129b3%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/bcec4757-542a-4a28-b94c-71fb23d129b3%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/bcec4757-542a-4a28-b94c-71fb23d129b3%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/bcec4757-542a-4a28-b94c-71fb23d129b3%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .
> 
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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/CAKdsXoGTiS3yKNGv6VU3uOas9h6pOR8SwH%2BfrVOkkMVNFnsP2Q%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAKdsXoGTiS3yKNGv6VU3uOas9h6pOR8SwH%2BfrVOkkMVNFnsP2Q%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 12:58am UTC](https://discuss.elastic.co/t/checking-update-results/20019/7 "2017-07-06T00:58:53Z")

</div>


