# Scroll and sort or retricve indexing order

**URL:** <https://discuss.elastic.co/t/scroll-and-sort-or-retricve-indexing-order/46678>\
**Category:** Elasticsearch\
**Created:** [April 7, 2016, 12:44pm UTC](https://discuss.elastic.co/t/scroll-and-sort-or-retricve-indexing-order/46678 "2016-04-07T12:44:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stesig](https://avatars.discourse-cdn.com/v4/letter/s/db5fbb/32.png) [@Stesig](https://discuss.elastic.co/u/Stesig)\
**Post date:** [April 7, 2016, 12:44pm UTC](https://discuss.elastic.co/t/scroll-and-sort-or-retricve-indexing-order/46678/1 "2016-04-07T12:44:52Z")

</div>

Hi there,  
I need a fast search that gives me a big number of sorted result items. Currently I'm using scroll function or scroll/scan function and sort them outside es (order by timestamp). But here I can not solve the right order for docs with same timestamp.  
I tried to use scroll function without scan mode but the response is sorted only partially and not at all.

Here my query  
String query = "{"constant\_score": {"filter": {"and": [{"terms": {"termname": ["value"]}}]}}},"sort":{"timestamp":{"order":"asc"}}"

SearchRequestBuilder requestBuilder = client.getClient().prepareSearch(index)  
.setScroll(new TimeValue(timeval))  
.setQuery(query);

I want sorting done inside of es to solve the problem with data with same timestamp. What would be the best aproach?

Thanks for replaying

---

<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:01pm UTC](https://discuss.elastic.co/t/scroll-and-sort-or-retricve-indexing-order/46678/2 "2017-07-05T23:01:32Z")

</div>


