# Elasticsearch response order consistency issues

**URL:** <https://discuss.elastic.co/t/elasticsearch-response-order-consistency-issues/281767>\
**Category:** Elasticsearch\
**Created:** [August 18, 2021, 5:52am UTC](https://discuss.elastic.co/t/elasticsearch-response-order-consistency-issues/281767 "2021-08-18T05:52:47Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![govind\_kr](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/govind_kr/32/80282_2.png) [@govind\_kr](https://discuss.elastic.co/u/govind_kr)\
**Post date:** [August 18, 2021, 5:52am UTC](https://discuss.elastic.co/t/elasticsearch-response-order-consistency-issues/281767/1 "2021-08-18T05:52:47Z")

</div>

I have been facing issues related to es response order which is getting reshuffled even though I am not querying on the fields (I have made them non-indexed so as to ignore them in scoring) and performing dfs\_query\_then\_fetch query. Moreover, those non-indexed fields are updated in every hit to elasticsearch.

Any suggestions on how to resolve this issue?

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [August 18, 2021, 6:05am UTC](https://discuss.elastic.co/t/elasticsearch-response-order-consistency-issues/281767/2 "2021-08-18T06:05:02Z")

</div>

I am not sure I understand. Can you please provide an example?

---

<div class="post-metadata">

**Author:** ![govind\_kr](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/govind_kr/32/80282_2.png) [@govind\_kr](https://discuss.elastic.co/u/govind_kr)\
**Post date:** [August 18, 2021, 6:23am UTC](https://discuss.elastic.co/t/elasticsearch-response-order-consistency-issues/281767/3 "2021-08-18T06:23:45Z")

</div>

Let's say there are 10 documents out of which 7 are indexed(by default) and remaining 3 are non-indexed (index: false), so now I am updating values to those non-indexed fields in each and every hit to es. At the same time, querying is happening over indexed fields as we can't query over non-indexed fields. Here comes the issue, for each query, the response order are not consistent, their order is getting changed even though the score is constant for the changed order (entity / doc).

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [August 18, 2021, 6:41am UTC](https://discuss.elastic.co/t/elasticsearch-response-order-consistency-issues/281767/4 "2021-08-18T06:41:19Z")

</div>

What is the score for the documents returned? Are you applying any sorting to the query?

---

<div class="post-metadata">

**Author:** ![govind\_kr](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/govind_kr/32/80282_2.png) [@govind\_kr](https://discuss.elastic.co/u/govind_kr)\
**Post date:** [August 18, 2021, 6:48am UTC](https://discuss.elastic.co/t/elasticsearch-response-order-consistency-issues/281767/5 "2021-08-18T06:48:27Z")

</div>

I am not applying any sorting to the query. only filters are being used.

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [August 18, 2021, 7:04am UTC](https://discuss.elastic.co/t/elasticsearch-response-order-consistency-issues/281767/6 "2021-08-18T07:04:31Z")

</div>

If all the documents have the same score as only filters are used and no sorting is applied I do not think ordering is guaranteed.

---

<div class="post-metadata">

**Author:** ![govind\_kr](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/govind_kr/32/80282_2.png) [@govind\_kr](https://discuss.elastic.co/u/govind_kr)\
**Post date:** [August 18, 2021, 9:06am UTC](https://discuss.elastic.co/t/elasticsearch-response-order-consistency-issues/281767/7 "2021-08-18T09:06:33Z")

</div>

Just to add, let's say there are 50 responses, out of which 20 have same scores, within that 20 responses, the orders are getting changed.  
Even if the filters are used, all the docs have same scores, that way order is inconsistent.  
@Sriram8894 FYI

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [August 18, 2021, 10:23am UTC](https://discuss.elastic.co/t/elasticsearch-response-order-consistency-issues/281767/8 "2021-08-18T10:23:11Z")

</div>

I would recommend you specify a sort order if you want/need consistency, e.g. score first and \_doc second as a tie-breaker.

---

<div class="post-metadata">

**Author:** ![govind\_kr](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/govind_kr/32/80282_2.png) [@govind\_kr](https://discuss.elastic.co/u/govind_kr)\
**Post date:** [August 18, 2021, 10:25am UTC](https://discuss.elastic.co/t/elasticsearch-response-order-consistency-issues/281767/9 "2021-08-18T10:25:19Z")

</div>

I tried by applying sort order as well, still I am facing the same inconsistent behaviour.

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [August 18, 2021, 10:33am UTC](https://discuss.elastic.co/t/elasticsearch-response-order-consistency-issues/281767/10 "2021-08-18T10:33:34Z")

</div>

What sort order did you apply? Maybe try score and \_id?

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [August 18, 2021, 9:11pm UTC](https://discuss.elastic.co/t/elasticsearch-response-order-consistency-issues/281767/11 "2021-08-18T21:11:14Z")

</div>

It'd help if you could provide code examples of what you want to do, what you are running, and what you are seeing.

---

<div class="post-metadata">

**Author:** ![govind\_kr](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/govind_kr/32/80282_2.png) [@govind\_kr](https://discuss.elastic.co/u/govind_kr)\
**Post date:** [August 19, 2021, 9:56am UTC](https://discuss.elastic.co/t/elasticsearch-response-order-consistency-issues/281767/12 "2021-08-19T09:56:18Z")

</div>

Let's say there are 10 fields inside a document out of which 7 fields are indexed(by default) and remaining 3 are non-indexed (index: false), so now I am updating values to those non-indexed fields in each and every hit to es. At the same time, querying is happening over indexed fields as we can't query over non-indexed fields. Here comes the issue, for each query, the response order are not consistent, their order is getting changed even though the score is constant for the changed order (entity / doc).

@Christian_Dahlqvist

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [August 19, 2021, 9:59am UTC](https://discuss.elastic.co/t/elasticsearch-response-order-consistency-issues/281767/13 "2021-08-19T09:59:32Z")

</div>

Please show a complete example and specify how you are sorting and what the score of the matches are.

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [August 19, 2021, 10:03pm UTC](https://discuss.elastic.co/t/elasticsearch-response-order-consistency-issues/281767/14 "2021-08-19T22:03:36Z")

</div>

2 posts were split to a new topic: [Filtering and ordering](https://discuss.elastic.co/t/filtering-and-ordering/282015)

---

<div class="post-metadata">

**Author:** ![Randall-McRee](https://avatars.discourse-cdn.com/v4/letter/r/e8c25b/32.png) [@Randall-McRee](https://discuss.elastic.co/u/Randall-McRee)\
**Post date:** [August 21, 2021, 4:32am UTC](https://discuss.elastic.co/t/elasticsearch-response-order-consistency-issues/281767/15 "2021-08-21T04:32:34Z")

</div>

There is some basic misunderstanding here. All documents are indexed by definition. Within a document there are fields which may or may not be searchable. If you update a single field or put a complete new doc into the index it may or may not be immediately visible to a search, this depends upon the refresh setting. Elasticsearch is a non sql database and this loose connection between updates and searches is considered a strength, not a bug! Consider that sql requires the whole mechanism of transactions to tightly specify the coordination of updates with queries.  
So, as mentioned earlier a worked example is best, from you, in order to help further.

---

<div class="post-metadata">

**Author:** ![govind\_kr](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/govind_kr/32/80282_2.png) [@govind\_kr](https://discuss.elastic.co/u/govind_kr)\
**Post date:** [August 24, 2021, 9:16am UTC](https://discuss.elastic.co/t/elasticsearch-response-order-consistency-issues/281767/16 "2021-08-24T09:16:00Z")

</div>

@Christian_Dahlqvist Find the query below:

"sort": [{  
"\_geo\_distance": {  
"latlong": [{  
"lat": 26.8756,  
"lon": 80.9115  
}],  
"unit": "mi",  
"distance\_type": "arc",  
"order": "asc",  
"validation\_method": "STRICT",  
"ignore\_unmapped": false  
}  
}]

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [August 24, 2021, 9:36am UTC](https://discuss.elastic.co/t/elasticsearch-response-order-consistency-issues/281767/17 "2021-08-24T09:36:55Z")

</div>

Please provide a full example for reproduction including sample data, mappings and queries. It would also help if you showed the result you are getting with this sample data and highlight how this differs from what you expect/desire.

---

<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:** [September 21, 2021, 9:37am UTC](https://discuss.elastic.co/t/elasticsearch-response-order-consistency-issues/281767/18 "2021-09-21T09:37:13Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
