# Pagination with from doesn't work

**URL:** <https://discuss.elastic.co/t/pagination-with-from-doesnt-work/61777>\
**Category:** Elasticsearch\
**Created:** [September 29, 2016, 7:30am UTC](https://discuss.elastic.co/t/pagination-with-from-doesnt-work/61777 "2016-09-29T07:30:47Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![barry1](https://avatars.discourse-cdn.com/v4/letter/b/7bcc69/32.png) [@barry1](https://discuss.elastic.co/u/barry1)\
**Post date:** [September 29, 2016, 7:30am UTC](https://discuss.elastic.co/t/pagination-with-from-doesnt-work/61777/1 "2016-09-29T07:30:47Z")

</div>

I'm experiencing som strange behaviour when using `from` and `size`. My index contains 1941 documents, so when I do a search with `from=1940&size=10` then I'm expecting only the last document, but I'm allways getting the first 10 documents no mather what I'm saying the `from` should be.

> GET my-index/my-type/\_search?search\_type=query\_then\_fetch&scroll=30s&from=1940&size=10

I'm using Elasticsearch version 2.3.1.

Any thoughts?

---

<div class="post-metadata">

**Author:** ![ayushbij27](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ayushbij27/32/24314_2.png) [@ayushbij27](https://discuss.elastic.co/u/ayushbij27)\
**Post date:** [September 29, 2016, 8:20am UTC](https://discuss.elastic.co/t/pagination-with-from-doesnt-work/61777/2 "2016-09-29T08:20:58Z")

</div>

Yes , it is supposed to return only the last document ,try this query.

curl -XGET "[http://youripaddress:9200/indexname/indextype/\_search?pretty](http://youripaddress:9200/indexname/indextype/_search?pretty)" -d'  
{  
"query": {  
"match\_all": {}  
},  
"from":1940,  
"size": 10

}'

---

<div class="post-metadata">

**Author:** ![barry1](https://avatars.discourse-cdn.com/v4/letter/b/7bcc69/32.png) [@barry1](https://discuss.elastic.co/u/barry1)\
**Post date:** [September 29, 2016, 8:47am UTC](https://discuss.elastic.co/t/pagination-with-from-doesnt-work/61777/3 "2016-09-29T08:47:51Z")

</div>

This works in sense, I'm now getting the last document.

But with the PHP client I still can't get it to work properly, below is the code I'm using:

```
$aParams = array(
	'search_type' => 'scan',
	'scroll' => '30s',
	'index' => 'my-index',
	'type' => 'my-type',
	'from' => 1900,
	'size' => 25, /** we have 4 shards, so it should return 100 docs and 41 for the last page */
	'body' => array(
		'query' => array(
			'bool' => array(
				'must' => array(
					array( 'match' => array( 'status' => 'active' ) ),
				)
			)
		)
	)
);
```

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [September 29, 2016, 9:03am UTC](https://discuss.elastic.co/t/pagination-with-from-doesnt-work/61777/4 "2016-09-29T09:03:04Z")

</div>

You should remove these lines from your code

> [@barry1](#):
>
> 'search\_type' =\> 'scan',  
> 'scroll' =\> '30s',

---

<div class="post-metadata">

**Author:** ![barry1](https://avatars.discourse-cdn.com/v4/letter/b/7bcc69/32.png) [@barry1](https://discuss.elastic.co/u/barry1)\
**Post date:** [September 29, 2016, 9:07am UTC](https://discuss.elastic.co/t/pagination-with-from-doesnt-work/61777/5 "2016-09-29T09:07:29Z")

</div>

Now I'm getting no results.

Why should I remove these lines? Does the `from` parameter not work with `scan`?

---

<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:16pm UTC](https://discuss.elastic.co/t/pagination-with-from-doesnt-work/61777/6 "2017-07-05T22:16:13Z")

</div>


