SharePoint Online:列表的REST API,调用筛选器并限制返回项目

问题描述 投票:2回答:3

我正在尝试使用以下REST API来调用REST API以获取列表

https://myweb.sharepoint.com/teams/sites/subwebs/_api/web/lists/GetByTitle('MyList')/Items?
$top=1
&$orderby=ID
&$select=ID,FName,LName,Title
&$filter=Title eq 'Female'

我需要$ filter应该与限制为$ top的记录数一起使用。如果未应用$ filter,则$ top有效。

嗯,我的列表包含超过5000个项目。在对上述URL进行GET请求时,收到以下错误消息

{
"readyState": 4,
"responseText": "{\"odata.error\":{\"code\":\"-2147024860, Microsoft.SharePoint.SPQueryThrottledException\",\"message\":{\"lang\":\"en-US\",\"value\":\"The attempted operation is prohibited because it exceeds the list view threshold enforced by the administrator.\"}}}",
"responseJSON": {
    "odata.error": {
        "code": "-2147024860, Microsoft.SharePoint.SPQueryThrottledException",
        "message": {
            "lang": "en-US",
            "value": "The attempted operation is prohibited because it exceeds the list view threshold enforced by the `enter code here`administrator."
        }
    }
},
"status": 500,
"statusText": "Internal Server Error"
}
rest sharepoint-online
3个回答
4
投票

由于Microsoft.SharePoint.SPQueryThrottledException查询导致遍历整个列表并检查每一行以查看是否匹配,因此引发$filter=Title eq 'Female'异常。

根据MSDN

列表视图阈值不仅仅适用于结果数由您的查询返回。相反,它限制了数据库的数量可以访问以完成查询执行的行在内容数据库中的行级别。

这就是$top查询选项在此处不适用的原因。

避免问题的一种选择是将Title字段编入索引。

转到List Settings -> Indexed Columns -> Create a new index -> select Title as a Primary Column

enter image description here

一旦Title字段被索引,以下查询应成功:

https://site/_api/web/lists/GetByTitle('<list title>')/Items?$top=1&$orderby=ID&$select=ID,Title&$filter=Title eq '<value>'

2
投票

我知道这听起来很明显,但是第一个过滤器必须返回5,000个或更少的项。然后,您可以添加其他过滤器。在这种情况下,您可能不需要$ top参数。例如:

https://site/_api/web/lists/GetByTitle('<List Title>')/Items?$filter=<Column Name> eq '<A value that you know returns 5,000 items or less>' and Title eq 'Female'

-1
投票
Promise.all([
rest call # 1 query : queryFilter:"ID lt '3000' and  Title eq '000672'"
rest call # 2 query : queryFilter:"ID gt '2999' and  Title eq '000672'"


.then( arr=> {
        let fullArr = [...a[0],...a[1]]
© www.soinside.com 2019 - 2024. All rights reserved.