3
votes

I'm using ms-graph with SharePoint Online. I've a simple list with a single title column and 3 items.

I use the following ms-graph call to filter items by title:

https://graph.microsoft.com/v1.0/sites/root:/lists/list-guid/items?expand=fields&filter=startswith(fields/Title,%27fig%27)

The result is an error message:

Field 'Title' cannot be referenced in filter or orderby as it is not indexed. Provide the 'Prefer: HonorNonIndexedQueriesWarningMayFailRandomly' header to allow this, but be warned that such queries may fail on large lists.

I know that this call was working before and also when I use SharePoint REST API then I can filter the list without any problems. I also tried different tenants. Another fact is that the same call is working without the startswith filter.

Few days ago I had a different message for the same call.

"Field 'Title' cannot be referenced in filter or orderby as it is not indexed. Provide the 'allowthrottleablequeries' preference to allow this, but be warned that such queries may fail on large lists."

2

2 Answers

10
votes

Regarding the following error:

Field 'Title' cannot be referenced in filter or orderby as it is not indexed. Provide the 'Prefer: HonorNonIndexedQueriesWarningMayFailRandomly' header to allow this, but be warned that such queries may fail on large lists.

at least two options are available to surpass this error while filtering.

Option 1. Add an index to a SharePoint column

Once the index to a SharePoint column which participates in filtering is created, the error should no longer appear.

enter image description here

Option 2. Append header Prefer:HonorNonIndexedQueriesWarningMayFailRandomly

As the error message states append the specified header to request, for example in Graph Explorer:

enter image description here

0
votes

Just checked the Graph API Explorer and found out that you can use allowthrottleablequeries rather than HonorNonIndexedQueriesWarningMayFailRandomly

Try to send your request with the following Request Header

Prefer: allowthrottleablequeries