# Different response for same query

**URL:** https://discuss.elastic.co/t/different-response-for-same-query/7509
**Category:** Elasticsearch
**Created:** [April 29, 2012, 3:48pm UTC](https://discuss.elastic.co/t/different-response-for-same-query/7509 "2012-04-29T15:48:10Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![barnash](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/barnash/32/2899_2.png) [@barnash](https://discuss.elastic.co/u/barnash)
#### Post date: [April 29, 2012, 3:48pm UTC](https://discuss.elastic.co/t/different-response-for-same-query/7509/1 "2012-04-29T15:48:10Z")

</div>

Hi,

We are running a query using the elastic search head application and  
it seems like we are getting the same results but in different order.  
The strangest thing is that every second time we run the query, we get  
the same result.  
So for example this is the query we run:

{  
"query": {  
"wildcard": {  
"foo": "bar\*"  
}  
}  
}

And here are the two results we are getting:  
Response A:  
Total: 3045177  
hits: a, b, c ,d, e...

Response B:  
Total: 3045177  
hits: f, g, h, i, j...

If we run the query again and again, we consistently get these  
results:  
A, B, A, B, A, B, A, B, ...

We don't understand why this is happening and how can we fix it.  
Can someone please advise?

Thanks,  
Iftach

---

<div class="post-metadata">

### Author: ![Klerisson](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/klerisson/32/2878_2.png) [@Klerisson](https://discuss.elastic.co/u/Klerisson)
#### Post date: [April 30, 2012, 11:59am UTC](https://discuss.elastic.co/t/different-response-for-same-query/7509/2 "2012-04-30T11:59:44Z")

</div>

I got the same once, but the problem was related to the CouchDB  
documents' revision.

Somehow the updated docs were not getting indexed by ES (river), and  
even more, I submitted the same query twice and got docs from the n-  
revision first and (n+1)-revision after.

Regards,

On Apr 29, 12:48 pm, barnash [iftach...@gmail.com](mailto:iftach...@gmail.com) wrote:

> Hi,
> 
> We are running a query using the Elasticsearch head application and  
> it seems like we are getting the same results but in different order.  
> The strangest thing is that every second time we run the query, we get  
> the same result.  
> So for example this is the query we run:
> 
> {  
> "query": {  
> "wildcard": {  
> "foo": "bar\*"  
> }  
> }
> 
> }
> 
> And here are the two results we are getting:  
> Response A:  
> Total: 3045177  
> hits: a, b, c ,d, e...
> 
> Response B:  
> Total: 3045177  
> hits: f, g, h, i, j...
> 
> If we run the query again and again, we consistently get these  
> results:  
> A, B, A, B, A, B, A, B, ...
> 
> We don't understand why this is happening and how can we fix it.  
> Can someone please advise?
> 
> Thanks,  
> Iftach

---

<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: [May 1, 2012, 2:56pm UTC](https://discuss.elastic.co/t/different-response-for-same-query/7509/3 "2012-05-01T14:56:55Z")

</div>

Order between same score documents is not guaranteed, especially when a  
search will hit different copies of a shard. Wildcard queries usually end  
up being a constant score query (and are expensive to execute, don't use  
them, use ngram based indexing instead).

You can provide a preference flag to the search request, for example, a  
session id or something similar, so a "user" will always hit the same shard  
and get a bit more consistent results. See more here:  
[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/preference.html).

On Sun, Apr 29, 2012 at 6:48 PM, barnash [iftachbar@gmail.com](mailto:iftachbar@gmail.com) wrote:

> Hi,
> 
> We are running a query using the Elasticsearch head application and  
> it seems like we are getting the same results but in different order.  
> The strangest thing is that every second time we run the query, we get  
> the same result.  
> So for example this is the query we run:
> 
> {  
> "query": {  
> "wildcard": {  
> "foo": "bar\*"  
> }  
> }  
> }
> 
> And here are the two results we are getting:  
> Response A:  
> Total: 3045177  
> hits: a, b, c ,d, e...
> 
> Response B:  
> Total: 3045177  
> hits: f, g, h, i, j...
> 
> If we run the query again and again, we consistently get these  
> results:  
> A, B, A, B, A, B, A, B, ...
> 
> We don't understand why this is happening and how can we fix it.  
> Can someone please advise?
> 
> Thanks,  
> Iftach

---

<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:30am UTC](https://discuss.elastic.co/t/different-response-for-same-query/7509/4 "2017-07-06T03:30:26Z")

</div>


