# No active shards in tests using the java api

**URL:** <https://discuss.elastic.co/t/no-active-shards-in-tests-using-the-java-api/9380>\
**Category:** Elasticsearch\
**Created:** [October 16, 2012, 2:38pm UTC](https://discuss.elastic.co/t/no-active-shards-in-tests-using-the-java-api/9380 "2012-10-16T14:38:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pascal\_Friederich](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pascal_friederich/32/2680_2.png) [@Pascal\_Friederich](https://discuss.elastic.co/u/Pascal_Friederich)\
**Post date:** [October 16, 2012, 2:38pm UTC](https://discuss.elastic.co/t/no-active-shards-in-tests-using-the-java-api/9380/1 "2012-10-16T14:38:12Z")

</div>

Hi,

I'm currently working with jruby and the java elasticsearch api. To ensure  
a clean index for every testcase, I delete, create and refresh the index  
before every test.  
This work's most of the time but sometimes I get the following exception:

```
org.elasticsearch.action.search.SearchPhaseExecutionException: Failed 

```

> to execute phase [query\_fetch], total failure; shardFailures  
> {[_na_][memento\_test][0]: No active shards}

What I'm doing is basically:

```
    def reset(index_name)
      client.prepare_delete(index_name).execute.action_get
      client.prepare_create(index_name).execute.action_get
      client.prepare_refresh(index_name).execute.action_get
    end

```

Nothing fancy I guess...  
I guess this is a timing problem but I currently can't think of a way to  
work around this.  
Any hints / best practices for these kind of test cleanups?

thanks!

-- pascal

--

---

<div class="post-metadata">

**Author:** ![Tanguy1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tanguy1/32/1749_2.png) [@Tanguy1](https://discuss.elastic.co/u/Tanguy1)\
**Post date:** [October 16, 2012, 3:12pm UTC](https://discuss.elastic.co/t/no-active-shards-in-tests-using-the-java-api/9380/2 "2012-10-16T15:12:02Z")

</div>

Have you tried to wait for a Green/Yellow cluster status before executing  
the tests/queries?

My 2 cents

-- Tanguy  
twitter: @tlrx

> **[tlrx - Overview](https://github.com/tlrx)**
>
> tlrx has 23 repositories available. Follow their code on GitHub.

Le mardi 16 octobre 2012 16:38:12 UTC+2, Pascal Friederich a écrit :

> Hi,
> 
> I'm currently working with jruby and the java elasticsearch api. To ensure  
> a clean index for every testcase, I delete, create and refresh the index  
> before every test.  
> This work's most of the time but sometimes I get the following exception:
> 
> ```
> org.elasticsearch.action.search.SearchPhaseExecutionException: Failed 
> 
> ```
> 
> > to execute phase [query\_fetch], total failure; shardFailures  
> > {[_na_][memento\_test][0]: No active shards}
> 
> What I'm doing is basically:
> 
> ```
> def reset(index_name)
> client.prepare_delete(index_name).execute.action_get
> client.prepare_create(index_name).execute.action_get
> client.prepare_refresh(index_name).execute.action_get
> end
> 
> ```
> 
> Nothing fancy I guess...  
> I guess this is a timing problem but I currently can't think of a way to  
> work around this.  
> Any hints / best practices for these kind of test cleanups?
> 
> thanks!
> 
> -- pascal

--

---

<div class="post-metadata">

**Author:** ![Pascal\_Friederich](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pascal_friederich/32/2680_2.png) [@Pascal\_Friederich](https://discuss.elastic.co/u/Pascal_Friederich)\
**Post date:** [October 16, 2012, 3:19pm UTC](https://discuss.elastic.co/t/no-active-shards-in-tests-using-the-java-api/9380/3 "2012-10-16T15:19:35Z")

</div>

heya, not quite, but you hinted me into the right direction. I'm executing  
a HealthRequest with waitForActiveShards(1) now. This seems to work so far

On Tuesday, October 16, 2012 5:12:02 PM UTC+2, Tanguy wrote:

> Have you tried to wait for a Green/Yellow cluster status before executing  
> the tests/queries?
> 
> My 2 cents
> 
> -- Tanguy  
> twitter: @tlrx  
> [tlrx (Tanguy Leroux) · GitHub](https://github.com/tlrx)
> 
> Le mardi 16 octobre 2012 16:38:12 UTC+2, Pascal Friederich a écrit :
> 
> > Hi,
> > 
> > I'm currently working with jruby and the java elasticsearch api. To  
> > ensure a clean index for every testcase, I delete, create and refresh the  
> > index before every test.  
> > This work's most of the time but sometimes I get the following exception:
> > 
> > ```
> > org.elasticsearch.action.search.SearchPhaseExecutionException: Failed 
> > 
> > ```
> > 
> > > to execute phase [query\_fetch], total failure; shardFailures  
> > > {[_na_][memento\_test][0]: No active shards}
> > 
> > What I'm doing is basically:
> > 
> > ```
> > def reset(index_name)
> > client.prepare_delete(index_name).execute.action_get
> > client.prepare_create(index_name).execute.action_get
> > client.prepare_refresh(index_name).execute.action_get
> > end
> > 
> > ```
> > 
> > Nothing fancy I guess...  
> > I guess this is a timing problem but I currently can't think of a way to  
> > work around this.  
> > Any hints / best practices for these kind of test cleanups?
> > 
> > thanks!
> > 
> > -- pascal

--

---

<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:08am UTC](https://discuss.elastic.co/t/no-active-shards-in-tests-using-the-java-api/9380/4 "2017-07-06T03:08:29Z")

</div>


