# Problem searchingh after update

**URL:** <https://discuss.elastic.co/t/problem-searchingh-after-update/15207>\
**Category:** Elasticsearch\
**Created:** [January 11, 2014, 12:07pm UTC](https://discuss.elastic.co/t/problem-searchingh-after-update/15207 "2014-01-11T12:07:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ukyo\_Virgden](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ukyo_virgden/32/1860_2.png) [@Ukyo\_Virgden](https://discuss.elastic.co/u/Ukyo_Virgden)\
**Post date:** [January 11, 2014, 12:07pm UTC](https://discuss.elastic.co/t/problem-searchingh-after-update/15207/1 "2014-01-11T12:07:25Z")

</div>

Hi,

I've just updated to 0.90.10 from 0.90.5, and I'm having some issues with  
my unit tests.

Here's the outline of the test

TransportClient c = new TransportClient(settings).addTransportAddress(new  
InetSocketTransportAddress("localhost", 9300));  
SearchResponse res = c.prepareSearch().setIndices(TEST\_INDEX).addFields(  
LIST\_OF\_FIELDS).setQuery(QueryBuilders.matchQuery("id", "\<\>")).  
execute().actionGet();  
// do the update  
UpdateResponse updateRes = prepareUpdateRequestForDocument(indexName,document  
).setScript("\<\< UPDATE SCRIPT \>\>").execute().actionGet();

// via REST API, I see the modified document hence the update is applied.  
// sleep for a while and repeat search  
SearchResponse res = c.prepareSearch().setIndices(TEST\_INDEX).addFields(  
LIST\_OF\_FIELDS).setQuery(QueryBuilders.matchQuery("id", "\<\>")).  
execute().actionGet();

SearchHit hit = res.getHits().getAt(0);  
// the document returned in the second search is not the updated document.  
assert(check document) -\> fails

even if I issue

client.admin().indices().prepareRefresh(TEST\_INDEX).execute().actionGet();

or

client.admin().indices().prepareFlush(TEST\_INDEX).execute().actionGet();

Why am I receiving the non-updated old document from the Java API where I  
immediately see the updated document via rest api? What am I missing?

Thanks in advance,  
Ukyo

--  
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/71df3e92-cc2d-4b03-acd1-73330e7df914%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/71df3e92-cc2d-4b03-acd1-73330e7df914%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:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [January 14, 2014, 11:41am UTC](https://discuss.elastic.co/t/problem-searchingh-after-update/15207/2 "2014-01-14T11:41:49Z")

</div>

Hey,

can you check the update response, if it was successful? Usually a refresh  
should be sufficient? You are testing the REST API while you are running  
this test and the REST works and this test doesnt?

Also can you provide a complete snippet including indexation and all your  
calls? The above code doesnt compile and contains many placeholders, so we  
cannot a complete picture of what you are doing.. A gist would be great!  
Thanks!

--Alex

On Sat, Jan 11, 2014 at 1:07 PM, Ukyo Virgden [ukyovirgden@gmail.com](mailto:ukyovirgden@gmail.com) wrote:

> Hi,
> 
> I've just updated to 0.90.10 from 0.90.5, and I'm having some issues with  
> my unit tests.
> 
> Here's the outline of the test
> 
> TransportClient c = new TransportClient(settings).addTransportAddress(new  
> InetSocketTransportAddress("localhost", 9300));  
> SearchResponse res = c.prepareSearch().setIndices(TEST\_INDEX).addFields(  
> LIST\_OF\_FIELDS).setQuery(QueryBuilders.matchQuery("id", "\<\>")).  
> execute().actionGet();  
> // do the update  
> UpdateResponse updateRes = prepareUpdateRequestForDocument(indexName,document  
> ).setScript("\<\< UPDATE SCRIPT \>\>").execute().actionGet();
> 
> // via REST API, I see the modified document hence the update is applied.  
> // sleep for a while and repeat search  
> SearchResponse res = c.prepareSearch().setIndices(TEST\_INDEX).addFields(  
> LIST\_OF\_FIELDS).setQuery(QueryBuilders.matchQuery("id", "\<\>")).  
> execute().actionGet();
> 
> SearchHit hit = res.getHits().getAt(0);  
> // the document returned in the second search is not the updated document.  
> assert(check document) -\> fails
> 
> even if I issue
> 
> client.admin().indices().prepareRefresh(TEST\_INDEX).execute().actionGet();
> 
> or
> 
> client.admin().indices().prepareFlush(TEST\_INDEX).execute().actionGet();
> 
> Why am I receiving the non-updated old document from the Java API where I  
> immediately see the updated document via rest api? What am I missing?
> 
> Thanks in advance,  
> Ukyo
> 
> --  
> 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/71df3e92-cc2d-4b03-acd1-73330e7df914%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/71df3e92-cc2d-4b03-acd1-73330e7df914%40googlegroups.com)  
> .  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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/CAGCwEM\_0jF9XA0%3DgRs3%2BCaqLKyed%2BBFX0-y\_Ysj5Lh5UaQBZ-A%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGCwEM_0jF9XA0%3DgRs3%2BCaqLKyed%2BBFX0-y_Ysj5Lh5UaQBZ-A%40mail.gmail.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Ukyo\_Virgden](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ukyo_virgden/32/1860_2.png) [@Ukyo\_Virgden](https://discuss.elastic.co/u/Ukyo_Virgden)\
**Post date:** [January 16, 2014, 7:51pm UTC](https://discuss.elastic.co/t/problem-searchingh-after-update/15207/3 "2014-01-16T19:51:20Z")

</div>

Hi Alex,

It turns out that it was my fault. But this is a tricky one, I'd like to  
explain what happened for others to benefit. The issue was that I was not  
storing the field that I was updating. Therefore the getValue was returning  
empty from the Java API. The reason that I was able to see the updated  
document via REST api is that I was seeing the \_source field. So I went  
back to my mappings, and corrected the store attribute on the field.

Bottom line is \_source field already contains the whole document, there's  
little point in storing individual fields in Lucene other than highlight  
purposes.

Thanks for your answer.

On Tue, Jan 14, 2014 at 1:41 PM, Alexander Reelsen [alr@spinscale.de](mailto:alr@spinscale.de) wrote:

> Hey,
> 
> can you check the update response, if it was successful? Usually a refresh  
> should be sufficient? You are testing the REST API while you are running  
> this test and the REST works and this test doesnt?
> 
> Also can you provide a complete snippet including indexation and all your  
> calls? The above code doesnt compile and contains many placeholders, so we  
> cannot a complete picture of what you are doing.. A gist would be great!  
> Thanks!
> 
> --Alex
> 
> On Sat, Jan 11, 2014 at 1:07 PM, Ukyo Virgden [ukyovirgden@gmail.com](mailto:ukyovirgden@gmail.com)wrote:
> 
> > Hi,
> > 
> > I've just updated to 0.90.10 from 0.90.5, and I'm having some issues with  
> > my unit tests.
> > 
> > Here's the outline of the test
> > 
> > TransportClient c = new TransportClient(settings).addTransportAddress(new  
> > InetSocketTransportAddress("localhost", 9300));  
> > SearchResponse res = c.prepareSearch().setIndices(TEST\_INDEX).addFields(  
> > LIST\_OF\_FIELDS).setQuery(QueryBuilders.matchQuery("id", "\<\>")).  
> > execute().actionGet();  
> > // do the update  
> > UpdateResponse updateRes = prepareUpdateRequestForDocument(indexName,document  
> > ).setScript("\<\< UPDATE SCRIPT \>\>").execute().actionGet();
> > 
> > // via REST API, I see the modified document hence the update is applied.  
> > // sleep for a while and repeat search  
> > SearchResponse res = c.prepareSearch().setIndices(TEST\_INDEX).addFields(  
> > LIST\_OF\_FIELDS).setQuery(QueryBuilders.matchQuery("id", "\<\>")).  
> > execute().actionGet();
> > 
> > SearchHit hit = res.getHits().getAt(0);  
> > // the document returned in the second search is not the updated document.  
> > assert(check document) -\> fails
> > 
> > even if I issue
> > 
> > client.admin().indices().prepareRefresh(TEST\_INDEX).execute().actionGet  
> > ();
> > 
> > or
> > 
> > client.admin().indices().prepareFlush(TEST\_INDEX).execute().actionGet();
> > 
> > Why am I receiving the non-updated old document from the Java API where I  
> > immediately see the updated document via rest api? What am I missing?
> > 
> > Thanks in advance,  
> > Ukyo
> > 
> > --  
> > 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/71df3e92-cc2d-4b03-acd1-73330e7df914%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/71df3e92-cc2d-4b03-acd1-73330e7df914%40googlegroups.com)  
> > .  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> --  
> You received this message because you are subscribed to a topic in the  
> Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit  
> [https://groups.google.com/d/topic/elasticsearch/TmXih0KvEC0/unsubscribe](https://groups.google.com/d/topic/elasticsearch/TmXih0KvEC0/unsubscribe).  
> To unsubscribe from this group and all its topics, 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/CAGCwEM\_0jF9XA0%3DgRs3%2BCaqLKyed%2BBFX0-y\_Ysj5Lh5UaQBZ-A%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGCwEM_0jF9XA0%3DgRs3%2BCaqLKyed%2BBFX0-y_Ysj5Lh5UaQBZ-A%40mail.gmail.com)  
> .
> 
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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/CAHZHwzOXLVGQ2\_ipduJbjj92MYknwazankhbzqjWacLEH5wjkg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAHZHwzOXLVGQ2_ipduJbjj92MYknwazankhbzqjWacLEH5wjkg%40mail.gmail.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:56am UTC](https://discuss.elastic.co/t/problem-searchingh-after-update/15207/4 "2017-07-06T01:56:19Z")

</div>


