# Embedded ES used for unit testing not returning deterministic results

**URL:** <https://discuss.elastic.co/t/embedded-es-used-for-unit-testing-not-returning-deterministic-results/64282>\
**Category:** Elasticsearch\
**Created:** [October 28, 2016, 12:52pm UTC](https://discuss.elastic.co/t/embedded-es-used-for-unit-testing-not-returning-deterministic-results/64282 "2016-10-28T12:52:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ramdev\_Wudali](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ramdev_wudali/32/7894_2.png) [@Ramdev\_Wudali](https://discuss.elastic.co/u/Ramdev_Wudali)\
**Post date:** [October 28, 2016, 12:52pm UTC](https://discuss.elastic.co/t/embedded-es-used-for-unit-testing-not-returning-deterministic-results/64282/1 "2016-10-28T12:52:18Z")

</div>

Hi:  
I am using ES 2.3.4 and firing up an embedded ES instance to perform unitTesting  
(the test scenario is to query for a string against a custom analyzed field and make sure the results returned are in the same order every time. )

1. I fire up the ES instance in the @BEfore section of the unItTest, use the Node Client to create Index, and populate the index with content.

2. I end the bulk loading with the following two commands:  
client.admin().indices().prepareFlush(indexName).setForce(true).execute().get();  
client.admin().indices().prepareRefresh(indexName).execute().get();

3. I execute my query sorting first by score and then by field(not\_analyzed).

The result set is different typically from the 4 document that is returned. (the top 3 sometimes 4 documents are the same. However, the scores that are assigned to the documents (all result documents) are different every time.

Is this a known issue with embedded ES or am I missing a setting on my embedded ES instance so that I get back consistent results.

Thanks for the assistance

---

<div class="post-metadata">

**Author:** ![ywelsch](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ywelsch/32/7751_2.png) [@ywelsch](https://discuss.elastic.co/u/ywelsch)\
**Post date:** [October 28, 2016, 1:32pm UTC](https://discuss.elastic.co/t/embedded-es-used-for-unit-testing-not-returning-deterministic-results/64282/2 "2016-10-28T13:32:17Z")

</div>

I guess you have multiple shards. Have a look here:  
[https://www.elastic.co/guide/en/elasticsearch/guide/current/relevance-is-broken.html](https://www.elastic.co/guide/en/elasticsearch/guide/current/relevance-is-broken.html)

---

<div class="post-metadata">

**Author:** ![Ramdev\_Wudali](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ramdev_wudali/32/7894_2.png) [@Ramdev\_Wudali](https://discuss.elastic.co/u/Ramdev_Wudali)\
**Post date:** [October 28, 2016, 3:09pm UTC](https://discuss.elastic.co/t/embedded-es-used-for-unit-testing-not-returning-deterministic-results/64282/3 "2016-10-28T15:09:11Z")

</div>

Excellent, I had read the article but did not connect my issue with the post. Thanks much

Ramdev

---

<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 5, 2017, 10:08pm UTC](https://discuss.elastic.co/t/embedded-es-used-for-unit-testing-not-returning-deterministic-results/64282/4 "2017-07-05T22:08:42Z")

</div>


