Index on contenttype column breaks REST query on ContentTypeId

Brass Contributor

We have a REST query on a list with a filter on contentypeid:

 

http://portal/_api/Web/Lists/getByTitle('MyForms')/Items?$filter=startswith(ContentTypeId,'0x010101008801EC40791D47909E988DEB1A1B9EFD006D679758256E403D9B766451FDA53DBF')

 

This query has always worked. Our list now has more than 500 items and now the query fails and returning zero items. We have an expiration policy on our contenttypes. The expiration policy timer job has created an index on the contenttype column. When I remove this index my query works again with 500 or more items. sadly the index is recreated on contenttype when the expiration policy timer job runs.

 

Why does an index on contenttype break my REST query when there are 500 items or more? When I have 499 items the query still works even with the index on contentype

 

#### Update from analyzing the ULS log ####

 

When I do a trace I see that my REST query is translated to the following CAML query:

 

 

 

<Query><Where><BeginsWith><FieldRef Name='ContentTypeId' /><Value Type='Text'>0x010101008801EC40791D47909E988DEB1A1B9EFD006D679758256E403D9B766451FDA53DBF</Value></BeginsWith></Where></Query>

 

 

 

This query fails when I execute this from CSOM.

 

 

 

            using (ClientContext ctx = new ClientContext("http://d-ccp-portal"))
            {
                Web web = ctx.Web;
                List list = web.Lists.GetByTitle("Beheerde documenten Forms 2");

                var q = new CamlQuery() { ViewXml = "<View><Query><Where><BeginsWith><FieldRef Name='ContentTypeId' /><Value Type='Text'>0x010101008801EC40791D47909E988DEB1A1B9EFD006D679758256E403D9B766451FDA53DBF</Value></BeginsWith></Where></Query></View>" };
                var r = list.GetItems(q);                ctx.Load(r);                ctx.ExecuteQuery();
            }

 

 

 

 

r = 0

The problem seems to be the value type. When I replace my CAML query like so:

 

 

 

<Query><Where><BeginsWith><FieldRef Name='ContentTypeId' /><Value Type='ContentTypeId'>0x010101008801EC40791D47909E988DEB1A1B9EFD006D679758256E403D9B766451FDA53DBF</Value></BeginsWith></Where></Query>

 

 

 

 

I do get all my items

 

 

 

            using (ClientContext ctx = new ClientContext("http://d-ccp-portal"))
            {
                Web web = ctx.Web;
                List list = web.Lists.GetByTitle("Beheerde documenten Forms 2");

                var q2 = new CamlQuery() { ViewXml = "<View><Query><Where><BeginsWith><FieldRef Name='ContentTypeId' /><Value Type='ContentTypeId'>0x010101008801EC40791D47909E988DEB1A1B9EFD006D679758256E403D9B766451FDA53DBF</Value></BeginsWith></Where></Query></View>" };
                var r2 = list.GetItems(q2);                ctx.Load(r2);                ctx.ExecuteQuery();
            }

 

 

 

 

So the problem seems to be that REST doesn't set the correct "value type" when you do a $filter on startswith(ContenTypeId)

 

Why the index on my list also has influence I don't really know. Because when there is no index on contenttype the first query also works fine.

0 Replies