# Java SearchHits provides out-of-order results when sort order provided in query

**URL:** https://discuss.elastic.co/t/java-searchhits-provides-out-of-order-results-when-sort-order-provided-in-query/35110
**Category:** Elasticsearch
**Created:** [November 20, 2015, 1:46am UTC](https://discuss.elastic.co/t/java-searchhits-provides-out-of-order-results-when-sort-order-provided-in-query/35110 "2015-11-20T01:46:28Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![tbessie](https://avatars.discourse-cdn.com/v4/letter/t/a698b9/32.png) [@tbessie](https://discuss.elastic.co/u/tbessie)
#### Post date: [November 20, 2015, 1:46am UTC](https://discuss.elastic.co/t/java-searchhits-provides-out-of-order-results-when-sort-order-provided-in-query/35110/1 "2015-11-20T01:46:28Z")

</div>

I'm using Elasticsearch 1.5.2, and after doing a search that specifies a sort order; when I run the generated JSON (as copied from the Java objects), the results appear in the desired sorted order.

However, when I extract search results as below, the results aren't in the same order.

Unless I'm doing something wrong here, I expect that this version of Elasticsearch perhaps is using a non-ordered Collection to store the search hits, causing this to happen. Does anyone know if this is the case, and if there's a workaround?

Incidentally, I have the source jar for this version of Elasticsearch, but for some reason the com.elasticsearch.search subpackage is not included in that source jar...

- Tim

---

<div class="post-metadata">

### Author: ![tbessie](https://avatars.discourse-cdn.com/v4/letter/t/a698b9/32.png) [@tbessie](https://discuss.elastic.co/u/tbessie)
#### Post date: [November 20, 2015, 2:01am UTC](https://discuss.elastic.co/t/java-searchhits-provides-out-of-order-results-when-sort-order-provided-in-query/35110/2 "2015-11-20T02:01:48Z")

</div>

Nevermind, folks, I found out it's because I'm using the SCAN type query, which doesn't sort.

It pays to read ALL the documentation - sorry! 😉

- Tim

---

<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:37pm UTC](https://discuss.elastic.co/t/java-searchhits-provides-out-of-order-results-when-sort-order-provided-in-query/35110/3 "2017-07-05T23:37:06Z")

</div>


