You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/search/search-pagination-page-layout.md
+35-1Lines changed: 35 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -68,7 +68,7 @@ Count won't be affected by routine maintenance or other workloads on the search
68
68
69
69
By default, the search engine returns up to the first 50 matches. The top 50 are determined by search score, assuming the query is full text search or semantic search. Otherwise, the top 50 are an arbitrary order for exact match queries (where uniform "@searchScore=1.0" indicates arbitrary ranking).
70
70
71
-
To control the paging of all documents returned in a result set, add `$top` and `$skip` parameters to the query request. The following list explains the logic.
71
+
To control the paging of all documents returned in a result set, add `$top` and `$skip` parameters to the GET query request or `top` and `skip` to the POST query request. The following list explains the logic.
72
72
73
73
+ Return the first set of 15 matching documents plus a count of total matches: `GET /indexes/<INDEX-NAME>/docs?search=<QUERY STRING>&$top=15&$skip=0&$count=true`
74
74
@@ -101,6 +101,40 @@ On the service, assume a fifth document is added to the index in between query c
101
101
102
102
Notice that document 2 is fetched twice. This is because the new document 5 has a greater value for rating, so it sorts before document 2 and lands on the first page. While this behavior might be unexpected, it's typical of how a search engine behaves.
103
103
104
+
### Paging through large numbers of results
105
+
106
+
Using `$top` and `$skip` allows a search query to page through 100,000 results. A value greater than 100,000 may not be used for `$skip`. It's possible to work around this limitation if a field has the ["filterable"](./search-filters.md) and ["sortable"] attributes.
107
+
108
+
1. Issue a query to return a full page of sorted results.
109
+
```http
110
+
POST /indexes/good-books/docs/search?api-version=2020-06-30
111
+
{
112
+
"search": "divine secrets",
113
+
"top": 50,
114
+
"orderby": "id asc"
115
+
}
116
+
```
117
+
2. Choose the last result returned by the search query. An example result with only an "id" value is shown here.
118
+
```json
119
+
{
120
+
"id": "50"
121
+
}
122
+
```
123
+
3. Use that "id" value in a range query to fetch the next page of results. This "id" field should have unique values, otherwise pagination may include duplicate results.
124
+
```http
125
+
POST /indexes/good-books/docs/search?api-version=2020-06-30
126
+
{
127
+
"search": "divine secrets",
128
+
"top": 50,
129
+
"orderby": "id asc",
130
+
"filter": "id ge 50"
131
+
}
132
+
```
133
+
4. Pagination ends when the query returns 0 results.
134
+
135
+
> [!NOTE]
136
+
> The "filterable" and "sortable" attributes can only be enabled when a field is first added to an index, they cannot be enabled on an existing field.
137
+
104
138
## Ordering results
105
139
106
140
In a full text search query, results can be ranked by:
0 commit comments