searchAfter cannot work with terminateAfter properly


(Caleb Shan) #1

elastic version : 6.4.2

Let's say page size is 10, shard count is 1, the matched total hits is 100.
If we set terminateAfter to 10, we can optain the first page. Then we use searchAfter to get the second page, will get nothing. It seems the docs before searchAfter offset also increased the collect count, so it terminate more earlier than it should be.


(Jimferenczi) #2

Unlike terminate_after, search_after is only applied to the top documents collector, it doesn't filter documents that should be collected by aggregations for instance. This means that even if top documents are empty because search_after filtered them aggregations can have results since they see all documents that match the query no matter how search_after is set. If you want to achieve pagination and use terminate_after on top of it you'll need to use a query that filters the top documents returned by the previous page. What are your sort criteria ? Are you sorting by a field (multiple fields), is it numeric ? By score only ?


(system) closed #3

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.