【问题标题】:SharePoint Online: REST API for List, calling Filters and limit the return itemsSharePoint Online:用于列表的 REST API,调用筛选器并限制返回项
【发布时间】:2017-03-14 17:36:19
【问题描述】:

我正在尝试使用以下 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


    【解决方案1】:

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

    根据MSDN

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

    这就是为什么$top 查询选项在这里不适用的原因。

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

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

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

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

    【讨论】:

    • 我做了同样的事情,但仍然遇到同样的错误。 _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('ListName')/items?$top=1000&amp;$filter= ColumnName eq 'abc'"。这里ColumnName 被索引。 ColumnName 中有超过 5000 条记录的值为“abc”。我遇到了同样的错误。
    【解决方案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'
    

    【讨论】:

      【解决方案3】:
      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]]
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-08-28
        • 2018-08-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-11-21
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多