# Query-then-Fetch without sorting

**URL:** <https://discuss.elastic.co/t/query-then-fetch-without-sorting/28353>\
**Category:** Elasticsearch\
**Created:** [August 31, 2015, 1:14pm UTC](https://discuss.elastic.co/t/query-then-fetch-without-sorting/28353 "2015-08-31T13:14:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![aken](https://avatars.discourse-cdn.com/v4/letter/a/b38774/32.png) [@aken](https://discuss.elastic.co/u/aken)\
**Post date:** [August 31, 2015, 1:14pm UTC](https://discuss.elastic.co/t/query-then-fetch-without-sorting/28353/1 "2015-08-31T13:14:43Z")

</div>

I see from here:

> **[Understanding "Query Then Fetch" vs "DFS Query Then Fetch"
	  	 | Elastic](https://www.elastic.co/blog/understanding-query-then-fetch-vs-dfs-query-then-fetch?q=query%20fetch)**
>
> In our last article on starts-with phrase matching, we ran into a situation where the returned scores were suspicious. As a refresher, here is the query in question:$ curl -XGET localhost:9200/startsw...

that a default query-then-fetch action will request the number of documents from each shard and then sort the results to give a final document set.

Does this happen also if _no_ sort is specified? I'm assuming it does but just want to be sure.

---

<div class="post-metadata">

**Author:** ![aken](https://avatars.discourse-cdn.com/v4/letter/a/b38774/32.png) [@aken](https://discuss.elastic.co/u/aken)\
**Post date:** [September 1, 2015, 11:07am UTC](https://discuss.elastic.co/t/query-then-fetch-without-sorting/28353/2 "2015-09-01T11:07:20Z")

</div>

It looks as though a default score of 1 is used in the absence of any specified sort. From here:

> **[Sorting | Elasticsearch: The Definitive Guide \[2.x\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/guide/current/_sorting.html)**

> The default sort order is \_score descending. Filters have no bearing on \_score, and the missing-but-implied match\_all query just sets the \_score to a neutral value of 1 for all documents. In other words, all documents are considered to be equally relevant.

---

<div class="post-metadata">

**Author:** ![mvg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mvg/32/98890_2.png) [@mvg](https://discuss.elastic.co/u/mvg)\
**Post date:** [September 1, 2015, 11:54am UTC](https://discuss.elastic.co/t/query-then-fetch-without-sorting/28353/3 "2015-09-01T11:54:40Z")

</div>

The default is the sort by score and if the query is not specified or the filter is used then the score is emitted is always `1`. In sort sorting always happens.

If your don't care about ordering you can then sort by the internal Lucene id of a document. This is the efficient way of just fetching some docs via the \_search api, especially in the ES 2.0 beta and up. If you want to sort by internal id, you should use the `_doc` as field to sort by.

---

<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, 11:52pm UTC](https://discuss.elastic.co/t/query-then-fetch-without-sorting/28353/4 "2017-07-05T23:52:54Z")

</div>


