2020-06-01 16:43:06 -04:00
|
|
|
[discrete]
|
|
|
|
[[paginate-search-results]]
|
|
|
|
=== Paginate search results
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2020-06-01 16:43:06 -04:00
|
|
|
By default, the search API returns the top 10 matching documents.
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2020-06-01 16:43:06 -04:00
|
|
|
To paginate through a larger set of results, you can use the search API's `size`
|
|
|
|
and `from` parameters. The `size` parameter is the number of matching documents
|
|
|
|
to return. The `from` parameter is a zero-indexed offset from the beginning of
|
|
|
|
the complete result set that indicates the document you want to start with.
|
|
|
|
|
|
|
|
The following search API request sets the `from` offset to `5`, meaning the
|
|
|
|
request offsets, or skips, the first five matching documents.
|
|
|
|
|
|
|
|
The `size` parameter is `20`, meaning the request can return up to 20 documents,
|
|
|
|
starting at the offset.
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2019-09-09 12:35:50 -04:00
|
|
|
[source,console]
|
2020-06-01 16:43:06 -04:00
|
|
|
----
|
2016-05-18 05:54:41 -04:00
|
|
|
GET /_search
|
2013-08-28 19:24:34 -04:00
|
|
|
{
|
2020-06-01 16:43:06 -04:00
|
|
|
"from": 5,
|
|
|
|
"size": 20,
|
|
|
|
"query": {
|
2020-07-21 16:14:44 -04:00
|
|
|
"match": {
|
|
|
|
"user.id": "kimchy"
|
2020-06-04 15:34:10 -04:00
|
|
|
}
|
2020-06-01 16:43:06 -04:00
|
|
|
}
|
2013-08-28 19:24:34 -04:00
|
|
|
}
|
2020-06-01 16:43:06 -04:00
|
|
|
----
|
2016-05-18 05:54:41 -04:00
|
|
|
|
2020-06-01 16:43:06 -04:00
|
|
|
By default, you cannot page through more than 10,000 documents using the `from`
|
|
|
|
and `size` parameters. This limit is set using the
|
|
|
|
<<index-max-result-window,`index.max_result_window`>> index setting.
|
2015-08-28 14:16:45 -04:00
|
|
|
|
2020-06-01 16:43:06 -04:00
|
|
|
Deep paging or requesting many results at once can result in slow searches.
|
|
|
|
Results are sorted before being returned. Because search requests usually span
|
|
|
|
multiple shards, each shard must generate its own sorted results. These separate
|
|
|
|
results must then be combined and sorted to ensure that the overall sort order
|
|
|
|
is correct.
|
|
|
|
|
2020-06-01 18:01:46 -04:00
|
|
|
As an alternative to deep paging, we recommend using
|
|
|
|
<<request-body-search-scroll,scroll>> or the
|
|
|
|
<<request-body-search-search-after,`search_after`>> parameter.
|
2019-08-22 21:22:54 -04:00
|
|
|
|
|
|
|
WARNING: {es} uses Lucene's internal doc IDs as tie-breakers. These internal
|
|
|
|
doc IDs can be completely different across replicas of the same
|
|
|
|
data. When paginating, you might occasionally see that documents with the same
|
2020-06-01 16:43:06 -04:00
|
|
|
sort values are not ordered consistently.
|