I Get Code: invalidRequest Message: Field 'ContentType' cannot be referenced in filter or orderby as it is not indexed. But it is indexed

Viewed 24

I'm trying to do a query to sharepoint online via graph, but i get the error: 'One or more errors occurred. (Code: invalidRequest Message: Field 'ContentType' 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.

But I'm sure that i have indexed the column. In All the site there are mora than 28k item, but with the filter in my query i should be able to retrieve about 200 of them.

If i use HonorNonIndexedQueriesWarningMayFailRandomly i get: Message: The request is unprocessable because it uses too many resources

But if i use multiple more specific query to retrieve less item and then i join the result i'm able to retrive all the items (always using the header HonorNonIndexedQueriesWarningMayFailRandomly).

The query is:

graphServiceClient.Sites[SiteId].Lists[ListId].Items.Request()
                    .Filter("fields/" + dataQuery + " ge '" + Adate+ "' and fields/" + dataQuery + " le '" + AnotherDate + "'" + "and fields/ContentType eq 'AContentType' and (fields/AField eq 'AStatus' or fields/AField eq 'AnotherStatus')")
                    .Expand("fields($select=" + dataQuery + ",FileLeafRef,AField)")
                    .Header("Prefer", "HonorNonIndexedQueriesWarningMayFailRandomly")
                    .GetAsync().Result.ToList();

do anyone understand why it seems that contentType isn't indexed? Or how i can use the query without getting The request is unprocessable?

0 Answers
Related