# If I index a bunch of items, then search without waiting for the indexing to finish, I get "Failed to execute phase"

**URL:** https://discuss.elastic.co/t/if-i-index-a-bunch-of-items-then-search-without-waiting-for-the-indexing-to-finish-i-get-failed-to-execute-phase/21767
**Category:** Elasticsearch
**Created:** [January 22, 2015, 4:51am UTC](https://discuss.elastic.co/t/if-i-index-a-bunch-of-items-then-search-without-waiting-for-the-indexing-to-finish-i-get-failed-to-execute-phase/21767 "2015-01-22T04:51:49Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![TimOnGmail](https://avatars.discourse-cdn.com/v4/letter/t/7bcc69/32.png) [@TimOnGmail](https://discuss.elastic.co/u/TimOnGmail)
#### Post date: [January 22, 2015, 4:51am UTC](https://discuss.elastic.co/t/if-i-index-a-bunch-of-items-then-search-without-waiting-for-the-indexing-to-finish-i-get-failed-to-execute-phase/21767/1 "2015-01-22T04:51:49Z")

</div>

I have a situation where, using the Java API, I initiate a bunch of  
indexing operations, but throw away the Future object (I don't need the  
return status). This is so I can do a lot of indexing reasonably  
asynchronously, so I don't have to hold up the GUI that triggers these  
calls.

However, if I fire off these indexing operations, and immediately after do  
a search operation on the same index, I get the following exception:

Caused by: org.elasticsearch.action.search.SearchPhaseExecutionException:  
Failed to execute phase [init\_scan], all shards failed  
at  
org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.onFirstPhaseResult(TransportSearchTypeAction.java:233)  
[elasticsearch-1.4.1.jar:]  
at  
org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction$1.onFailure(TransportSearchTypeAction.java:179)  
[elasticsearch-1.4.1.jar:]  
at  
org.elasticsearch.search.action.SearchServiceTransportAction$23.run(SearchServiceTransportAction.java:565)  
[elasticsearch-1.4.1.jar:]  
at  
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)  
[rt.jar:1.7.0\_60]  
at  
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)  
[rt.jar:1.7.0\_60]  
... 1 more

... however, if I wait awhile after indexing before searching, the search  
succeeds, no errors.

Does anyone know what is going on there? Shouldn't initiating an index  
operation asynchronously not affect search operations made on the same  
client?

I'm using a TransportClient, the same one for all operations.

- Tim

--  
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/7be3f287-edb3-4979-93c0-38e98317a545%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/7be3f287-edb3-4979-93c0-38e98317a545%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![TimOnGmail](https://avatars.discourse-cdn.com/v4/letter/t/7bcc69/32.png) [@TimOnGmail](https://discuss.elastic.co/u/TimOnGmail)
#### Post date: [January 22, 2015, 4:55am UTC](https://discuss.elastic.co/t/if-i-index-a-bunch-of-items-then-search-without-waiting-for-the-indexing-to-finish-i-get-failed-to-execute-phase/21767/2 "2015-01-22T04:55:16Z")

</div>

I made a mistake in my statement above - I am using different  
TransportClients for the indexing and the searching... so, one is doing the  
indexing, and while that is going on, I'm doing the searching on a  
different one.

- Tim

> 

--  
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/5011f21b-cbde-4bb8-9630-895a9d4fc684%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/5011f21b-cbde-4bb8-9630-895a9d4fc684%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![TimOnGmail](https://avatars.discourse-cdn.com/v4/letter/t/7bcc69/32.png) [@TimOnGmail](https://discuss.elastic.co/u/TimOnGmail)
#### Post date: [January 22, 2015, 5:02am UTC](https://discuss.elastic.co/t/if-i-index-a-bunch-of-items-then-search-without-waiting-for-the-indexing-to-finish-i-get-failed-to-execute-phase/21767/3 "2015-01-22T05:02:36Z")

</div>

Final bit of info, and this seems important; one TransportClient is being  
run in one thread, the other in another... so it goes like this:

Thread 1: Fork Thread 1  
Thread 2: Create new TransportClient; Index list of items, not waiting for  
Future objects (i.e. not calling actionGet())  
Thread 1: While Thread 2 is running, create new TransportClient and do  
search

... that's when I get the exception above.

- Tim

> 

--  
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/6171a5f7-ee20-4f7b-9d41-a8d2016f2dd6%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/6171a5f7-ee20-4f7b-9d41-a8d2016f2dd6%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![TimOnGmail](https://avatars.discourse-cdn.com/v4/letter/t/7bcc69/32.png) [@TimOnGmail](https://discuss.elastic.co/u/TimOnGmail)
#### Post date: [January 22, 2015, 5:04am UTC](https://discuss.elastic.co/t/if-i-index-a-bunch-of-items-then-search-without-waiting-for-the-indexing-to-finish-i-get-failed-to-execute-phase/21767/4 "2015-01-22T05:04:27Z")

</div>

I wish I could just go back and edit prior postings. 🙂

... I should mention, if I do the above, but don't create 2 threads - that  
is, synchronously index each item, close the TransportClient, create  
another TransportClient and do the search, it works. So this is ONLY  
happening when the two actions are happening in different threads.

- Tim

> 

--  
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/8cb89867-d5fa-43f5-8325-d89a50ba5f82%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/8cb89867-d5fa-43f5-8325-d89a50ba5f82%40googlegroups.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:37am UTC](https://discuss.elastic.co/t/if-i-index-a-bunch-of-items-then-search-without-waiting-for-the-indexing-to-finish-i-get-failed-to-execute-phase/21767/5 "2017-07-06T00:37:20Z")

</div>


