Pagination with from doesn't work


#1

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?


(Ayushbij27) #2

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

curl -XGET "http://youripaddress:9200/indexname/indextype/_search?pretty" -d'
{
"query": {
"match_all": {}
},
"from":1940,
"size": 10

}'


#3

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' ) ),
				)
			)
		)
	)
);

(Adrien Grand) #4

You should remove these lines from your code


#5

Now I'm getting no results.

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


(system) #6