Target SharePoint environment
SharePoint Online
What SharePoint development model, framework, SDK or API is this about?
SharePoint REST API
Developer environment
No response
What browser(s) / client(s) have you tested
Additional environment details
- SharePoint Online
- Custom SPFx web part
- SPFx version: 1.23
- Search endpoint: /_api/search/postquery
- Results are displayed using paging with 10 results per page
- The issue occurs on multiple pages, multiple sites and on multiple tenants
- First observed: late august
Describe the bug / error
We are observing significantly inaccurate and inconsistent values for PrimaryQueryResult.RelevantResults.TotalRows when using the SharePoint Search REST API (/_api/search/postquery) and paging through the results using StartRow.
The same search query is executed for each page. The query parameters remain unchanged except for StartRow.
With StartRow = 0, returned TotalRows = 200
With StartRow = 10, returned TotalRows = 400
With StartRow = 20, returned TotalRows = 400
With StartRow = 30, returned TotalRows = 500
As we navigate further through the result set, the reported TotalRows progressively changes and eventually becomes much closer to the actual size of the result set (5,359 items)
The values are also observed to change when the same request is repeated over time.
We understand that TotalRows may be an estimate and therefore do not expect the value to always be exact. However, we would expect the estimate to remain reasonably stable when navigating through pages of the same query and provide a reasonable approximation of the result set size.
We also observe a similar issue when querying graph search (https://graph.microsoft.com/v1.0/search/query)
In that case the hitsContainers.total is wrong
Steps to reproduce
-
Execute a SharePoint Search REST API POST request against /_api/search/postquery
Use a query matching a relatively large result set and request 10 results:
RowLimit: 10
StartRow: 0
Read: TotalRows
-
Execute exactly the same search query with:
StartRow: 10
TotalRows changes
-
Repeat with:
StartRow: 20
TotalRows changes
-
Continue paging through the same query. The reported TotalRows progressively changes and becomes much closer to the actual result-set size
The search criteria and other request parameters remain unchanged throughout these requests; only StartRow changes.
Expected behavior
We understand that TotalRows can be an estimated rather than exact value. However, for the same query we would expect TotalRows to provide a reasonably representative estimate of the result-set size and to remain reasonably stable when navigating between consecutive pages.
For a result set containing thousands of items, an initial estimate of only 200 items is too inaccurate to be useful for pagination.
Changing only StartRow should also not cause the estimated total to increase dramatically as progressively more pages are requested.
Ideally, TotalRows should either provide a reasonably stable approximation of the total result count across pages or
provide a documented mechanism that clients can use to obtain a sufficiently accurate count for implementing pagination.
Target SharePoint environment
SharePoint Online
What SharePoint development model, framework, SDK or API is this about?
SharePoint REST API
Developer environment
No response
What browser(s) / client(s) have you tested
Additional environment details
Describe the bug / error
We are observing significantly inaccurate and inconsistent values for
PrimaryQueryResult.RelevantResults.TotalRowswhen using the SharePoint Search REST API (/_api/search/postquery) and paging through the results usingStartRow.The same search query is executed for each page. The query parameters remain unchanged except for
StartRow.With StartRow = 0, returned TotalRows = 200
With StartRow = 10, returned TotalRows = 400
With StartRow = 20, returned TotalRows = 400
With StartRow = 30, returned TotalRows = 500
As we navigate further through the result set, the reported
TotalRowsprogressively changes and eventually becomes much closer to the actual size of the result set (5,359 items)The values are also observed to change when the same request is repeated over time.
We understand that
TotalRowsmay be an estimate and therefore do not expect the value to always be exact. However, we would expect the estimate to remain reasonably stable when navigating through pages of the same query and provide a reasonable approximation of the result set size.We also observe a similar issue when querying graph search (
https://graph.microsoft.com/v1.0/search/query)In that case the
hitsContainers.totalis wrongSteps to reproduce
Execute a SharePoint Search REST API POST request against
/_api/search/postqueryUse a query matching a relatively large result set and request 10 results:
RowLimit: 10StartRow: 0Read:
TotalRowsExecute exactly the same search query with:
StartRow: 10TotalRowschangesRepeat with:
StartRow: 20TotalRowschangesContinue paging through the same query. The reported
TotalRowsprogressively changes and becomes much closer to the actual result-set sizeThe search criteria and other request parameters remain unchanged throughout these requests; only
StartRowchanges.Expected behavior
We understand that
TotalRowscan be an estimated rather than exact value. However, for the same query we would expectTotalRowsto provide a reasonably representative estimate of the result-set size and to remain reasonably stable when navigating between consecutive pages.For a result set containing thousands of items, an initial estimate of only 200 items is too inaccurate to be useful for pagination.
Changing only
StartRowshould also not cause the estimated total to increase dramatically as progressively more pages are requested.Ideally,
TotalRowsshould either provide a reasonably stable approximation of the total result count across pages orprovide a documented mechanism that clients can use to obtain a sufficiently accurate count for implementing pagination.