# Strange behavior with Java API

**URL:** <https://discuss.elastic.co/t/strange-behavior-with-java-api/4009>\
**Category:** Elasticsearch\
**Created:** [March 2, 2011, 2:05am UTC](https://discuss.elastic.co/t/strange-behavior-with-java-api/4009 "2011-03-02T02:05:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Curtis\_Caravone](https://avatars.discourse-cdn.com/v4/letter/c/e47c2d/32.png) [@Curtis\_Caravone](https://discuss.elastic.co/u/Curtis_Caravone)\
**Post date:** [March 2, 2011, 2:05am UTC](https://discuss.elastic.co/t/strange-behavior-with-java-api/4009/1 "2011-03-02T02:05:20Z")

</div>

Hi,

I'm trying out elasticsearch (0.15.0) through the Java API. To do so, I  
wrote a simple unit test that starts an embedded instance, indexes a  
document, then searches for the document:

> <https://gist.github.com/caravone/b204814d5f26b7040cc6>

If I remove the WriteConsistencyLevel.QUORUM setting from the indexing  
operation, then about half of the time, even after a refresh, I fail to find  
the document at search time (I thought the default consistency level was  
QUORUM or ALL).

If I change the write consistency to WriteConsistencyLevel.ALL, then the  
test seems to hang at the indexing step.

Any ideas?

Curtis

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [March 2, 2011, 3:13am UTC](https://discuss.elastic.co/t/strange-behavior-with-java-api/4009/2 "2011-03-02T03:13:09Z")

</div>

Heya, setting the write consistency is not relevant to this case (since the index request will wait for at least one shard to be available already, and with 1 replica, it does not matter). But, there is a problem (only applies when a new index is being allocated): [Searching while an index is being allocated and no active shards exists within a "shard replication group" can cause search "misses" · Issue #736 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/736) (already fixed).

Note, if you use the cluster health API after you create the index and wait for yellow status, then this problem will not happen.

-shay.banon  
On Wednesday, March 2, 2011 at 4:05 AM, Curtis Caravone wrote:

> Hi,
> 
> I'm trying out elasticsearch (0.15.0) through the Java API. To do so, I wrote a simple unit test that starts an embedded instance, indexes a document, then searches for the document: [Unit test with embedded elasticsearch · GitHub](https://gist.github.com/b204814d5f26b7040cc6)
> 
> If I remove the WriteConsistencyLevel.QUORUM setting from the indexing operation, then about half of the time, even after a refresh, I fail to find the document at search time (I thought the default consistency level was QUORUM or ALL).
> 
> If I change the write consistency to WriteConsistencyLevel.ALL, then the test seems to hang at the indexing step.
> 
> Any ideas?
> 
> Curtis

---

<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, 4:11am UTC](https://discuss.elastic.co/t/strange-behavior-with-java-api/4009/3 "2017-07-06T04:11:04Z")

</div>


