# Scan and scroll in php land

**URL:** <https://discuss.elastic.co/t/scan-and-scroll-in-php-land/48527>\
**Category:** Elasticsearch\
**Created:** [April 27, 2016, 9:32am UTC](https://discuss.elastic.co/t/scan-and-scroll-in-php-land/48527 "2016-04-27T09:32:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tswider](https://avatars.discourse-cdn.com/v4/letter/t/f07891/32.png) [@tswider](https://discuss.elastic.co/u/tswider)\
**Post date:** [April 27, 2016, 9:32am UTC](https://discuss.elastic.co/t/scan-and-scroll-in-php-land/48527/1 "2016-04-27T09:32:50Z")

</div>

Hello, Can anybody tell me how can I scroll through a large index to get all the documents out ordered by time stamp?  
my parameters to initial search are :

`[

```
        'search_type' => 'scan',
        'scroll' => '2m',
        'size' => 100,
        'index' => $index,
        'body' => [
            'query' => $query,
            'sort' => [
               '@ts' => [
                    'order' => 'asc'
                ]
            ]
        ]
    ];`

```

but the documents comes out in random order.

---

<div class="post-metadata">

**Author:** ![dakrone](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dakrone/32/23351_2.png) [@dakrone](https://discuss.elastic.co/u/dakrone)\
**Post date:** [April 27, 2016, 5:04pm UTC](https://discuss.elastic.co/t/scan-and-scroll-in-php-land/48527/2 "2016-04-27T17:04:34Z")

</div>

Hi Tswider,

The scan/scroll API does not sort documents, it's meant to efficiently retrieve all the documents matching a query, so you won't be able to order the documents by the `order` field (as in your example)

---

<div class="post-metadata">

**Author:** ![tswider](https://avatars.discourse-cdn.com/v4/letter/t/f07891/32.png) [@tswider](https://discuss.elastic.co/u/tswider)\
**Post date:** [April 28, 2016, 7:16am UTC](https://discuss.elastic.co/t/scan-and-scroll-in-php-land/48527/3 "2016-04-28T07:16:05Z")

</div>

Thank you @dakrone, so is there any way of doing what I was trying to do ? geting large number (milions) of docs in a given order ?

---

<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, 10:55pm UTC](https://discuss.elastic.co/t/scan-and-scroll-in-php-land/48527/4 "2017-07-05T22:55:39Z")

</div>


