{"id":4563,"date":"2019-02-06T17:38:45","date_gmt":"2019-02-06T22:38:45","guid":{"rendered":"http:\/\/lisa.rushworth.us\/?p=4563"},"modified":"2019-02-06T17:53:21","modified_gmt":"2019-02-06T22:53:21","slug":"sharepoint-rest-api-does-not-allow-unindexed-queries","status":"publish","type":"post","link":"https:\/\/www.rushworth.us\/lisa\/?p=4563","title":{"rendered":"SharePoint Rest API Does Not Allow Unindexed Queries"},"content":{"rendered":"<p>I&#8217;ve been developing code templates for CRUD operations (that&#8217;s a real acronym &#8212; Create, Read, Update, Delete) against SharePoint &#8212; we need to use SharePoint lists to replace database tables. Retrieving information worked fine until I tried to filter the data through the REST call. SharePoint throws a generic error about exceeding some admin-set limit. (1) I know the limit, I can see the limit. The limit is 5,000, and I know my filtered result set is 121 records. WAY lower than 5,000. Oh, and (2) I can run the query without the filter &#8212; I&#8217;m paging it! &#8212; and read all 29,887 records so what does the limit have to do with anything? Reasoning with an HTTP response &#8230; well, doesn&#8217;t work. No matter how unassailable my argument is, the API call still returned:<\/p>\n<pre>{\"error\":\r\n    {\"code\":\"-2147024860, Microsoft.SharePoint.SPQueryThrottledException\",\r\n     \"message\":{\"lang\":\"en-US\",\r\n       \"value\":\"The attempted operation is prohibited because it exceeds the list \r\n                view threshold enforced by the administrator.\"}}}<\/pre>\n<p>It is, it turns out, a poorly worded error. I started thinking about the query limits on my LDAP servers &#8212; we have hard limits to operations and also require most people perform queries against indexed attributes. It&#8217;s computationally expensive to search through unindexed attributes (and the Right Thing To Do, generally speaking, is add an index for something that is a frequent query target). I wondered if there was an analogous &#8220;no unindexed queries&#8221; setting in SharePoint. Quick enough to test &#8212; add an index on the column(s) you use in the filter. In the site content listing, click the sideways hamburger menu by the list name. Select &#8220;Settings&#8221;<\/p>\n<p><a href=\"http:\/\/lisa.rushworth.us\/?attachment_id=4564\" rel=\"attachment wp-att-4564\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4564\" src=\"http:\/\/lisa.rushworth.us\/wp-content\/uploads\/2019\/02\/SPFilter01.png\" alt=\"\" width=\"991\" height=\"201\" srcset=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2019\/02\/SPFilter01.png 991w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2019\/02\/SPFilter01-300x61.png 300w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2019\/02\/SPFilter01-768x156.png 768w\" sizes=\"auto, (max-width: 991px) 100vw, 991px\" \/><\/a><\/p>\n<p>Scroll down to Index Columns and click the hyperlink.<\/p>\n<p><a href=\"http:\/\/lisa.rushworth.us\/?attachment_id=4565\" rel=\"attachment wp-att-4565\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4565\" src=\"http:\/\/lisa.rushworth.us\/wp-content\/uploads\/2019\/02\/SPFilter02.png\" alt=\"\" width=\"608\" height=\"250\" srcset=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2019\/02\/SPFilter02.png 608w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2019\/02\/SPFilter02-300x123.png 300w\" sizes=\"auto, (max-width: 608px) 100vw, 608px\" \/><\/a><\/p>\n<p>Click &#8216;Create a new index&#8217;<\/p>\n<p><a href=\"http:\/\/lisa.rushworth.us\/?attachment_id=4567\" rel=\"attachment wp-att-4567\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-4567\" src=\"http:\/\/lisa.rushworth.us\/wp-content\/uploads\/2019\/02\/SPFilter03-1-1024x203.png\" alt=\"\" width=\"960\" height=\"190\" srcset=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2019\/02\/SPFilter03-1-1024x203.png 1024w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2019\/02\/SPFilter03-1-300x59.png 300w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2019\/02\/SPFilter03-1-768x152.png 768w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2019\/02\/SPFilter03-1.png 1297w\" sizes=\"auto, (max-width: 960px) 100vw, 960px\" \/><\/a><\/p>\n<p>Wait for the index process to complete, <em>then<\/em> try the filtered request again &#8230; I&#8217;ve got data! Evidently SharePoint ODATA filter queries to the REST API need to be performed against indexed columns. I&#8217;m sure Microsoft has that documented <em>somewhere<\/em> but quite a bit of Googling didn&#8217;t get me anywhere &#8230; so I&#8217;m posting this in case anyone else encounters the same error.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve been developing code templates for CRUD operations (that&#8217;s a real acronym &#8212; Create, Read, Update, Delete) against SharePoint &#8212; we need to use SharePoint lists to replace database tables. Retrieving information worked fine until I tried to filter the data through the REST call. SharePoint throws a generic error about exceeding some admin-set limit. &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[33,677],"tags":[749,415,747,748],"class_list":["post-4563","post","type-post","status-publish","format-standard","hentry","category-coding","category-office-365","tag-odata","tag-sharepoint","tag-sharepoint-online","tag-spo"],"_links":{"self":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/4563","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4563"}],"version-history":[{"count":3,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/4563\/revisions"}],"predecessor-version":[{"id":4570,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/4563\/revisions\/4570"}],"wp:attachment":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4563"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4563"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4563"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}