A query built using the Sitecore Azure Content Search Provider doesn't produce the query that I was expecting. The result is that far too many results are returned. The purpose of the code is to find specific items in the index, not to search for matches based on a search term.

The code was initially built for Solr, and I'm sure it worked back then.

I think the issue is that Sitecore is using the search option rather than $filter.

The code I've used to create the predicate is as follows:

var predicate = PredicateBuilder.False<RelatedQualificationSearchResultItem>();

foreach (var codeParentPos in codeParentPosPairs)
    var innerPredicate = PredicateBuilder.True<RelatedQualificationSearchResultItem>();

    innerPredicate = innerPredicate.And(i => i.ParentPos == codeParentPos.ParentPos);

    if (!string.IsNullOrEmpty(codeParentPos.Code))
        innerPredicate = innerPredicate.And(i => i.QmdCode == codeParentPos.Code);

    predicate = predicate.Or(innerPredicate);

return predicate;

This is an example generated query (reduced to two inner predicates):

&search=(ParentPos:(1234\-56) AND QmdCode:(111/2222/3)) OR (ParentPos:(4321\-56) AND QmdCode:(333/2222/1))&queryType=full&$count=true

This returns over 250 results from the index.

Instead I want it to use a query like this:

&$filter=(ParentPos eq '1234-56' and QmdCode eq '111/2222/3') or (ParentPos eq '4321-56' and QmdCode eq '333/2222/1')&queryType=full&$count=true

This returns 2 results which in my opinion is what would be expected from the code written.

Is there anything I can do to make this behave as I'd expect? I don't want to have to resort to ditching the Sitecore provider again.

1 Answer 1


I received an answer from Sitecore Support and it seems there was a bug in the provider that was fixed in Sitecore 9.0 Update 2 (rev. 180604).

The fix doesn't use $filter, but it does wrap the search term in quotes and this makes the query work as expected.

If you can't upgrade to this version of Sitecore and need the patch you can ask Sitecore referencing bug #147386.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.