|
| 1 | +--- |
| 2 | +title: Pagination for large result sets |
| 3 | +ms.date: 10/14/2020 |
| 4 | +ms.prod: sharepoint |
| 5 | +localization_priority: Priority |
| 6 | +--- |
| 7 | + |
| 8 | +# Pagination for large result sets |
| 9 | + |
| 10 | +If you have a large number of search results (for example, over 50,000) to page through in a query, it is recommended to use the approach explained in this article instead of the approach of [StartRow](./sharepoint-search-rest-api-overview.md#startrow). This approach uses sorting on `[docid]` in ascending order and uses a query restriction on the `IndexDocId` value with an increasing value of `IndexDocID` for each new page. |
| 11 | + |
| 12 | +The advantages of this approach are: |
| 13 | + |
| 14 | +- It provides pagination with better performance |
| 15 | +- It does not have a limit on the number of pages (if you use the approach of [StartRow](./sharepoint-search-rest-api-overview.md#startrow) and the `StartRow` value is greater than 50,000, there is a risk of being throttled by SharePoint) |
| 16 | + |
| 17 | +Here is an example of using this approach: |
| 18 | + |
| 19 | +For Page 1, issue a query with sort on `[docid]` in ascending order: |
| 20 | + |
| 21 | +```http |
| 22 | +GET http://{site_url}/_api/search/query?querytext='sharepoint'&sortlist='[docid]:ascending' |
| 23 | +``` |
| 24 | + |
| 25 | +The result of this query should contain the following content: |
| 26 | + |
| 27 | +```xml |
| 28 | +... |
| 29 | +<d:element m:type="SP.SimpleDataRow"> |
| 30 | + <d:Cells> |
| 31 | + ... |
| 32 | + <d:element m:type="SP.KeyValue"> |
| 33 | + <d:Key>DocId</d:Key> |
| 34 | + <d:Value>10</d:Value> |
| 35 | + <d:ValueType>Edm.Int64</d:ValueType> |
| 36 | + </d:element> |
| 37 | + ... |
| 38 | +``` |
| 39 | + |
| 40 | +Get the `DocId` value of the last entry in the result. You should be able to find `DocId` under `SP.SimpleDataRow`. Let's say the `DocId` value is `10`. You will use that as the `DocID` restriction for page 2: |
| 41 | + |
| 42 | +For Page 2, use the following query, where you need to continue using sortlist on `DocId` in ascending order, but also add an `IndexDocId` restriction: |
| 43 | + |
| 44 | +```http |
| 45 | +GET http://{site_url}/_api/search/query?querytext='sharepoint indexdocid>10'&sortlist='[docid]:ascending' |
| 46 | +``` |
| 47 | + |
| 48 | +Let's say the `DocId` value of the last entry in the result is 20. |
| 49 | + |
| 50 | +For Page 3, continue the query with the same pattern as previous page: |
| 51 | + |
| 52 | +```http |
| 53 | +GET http://{site_url}/_api/search/query?querytext='sharepoint indexdocid>20'&sortlist='[docid]:ascending' |
| 54 | +``` |
| 55 | + |
| 56 | +And so on for the rest of the pages. |
0 commit comments