Back to Home

Azure search and multilist guid fields

SitecoreAzureSearch

Azure search and multilist guid fields

I ran into an issue the other day where I was trying to do a category search. Categories are stored in a multilist of guids. Originally I was following what I had been doing when working with SOLR / Lucene. This was to use a Contains predicate. But this wasn't working for me. I did a bit of research and came across this in the Sitecore documentation – "You must not apply queries such as StartsWith, Contains to fields with of type EDM.String that contain paths...or collections of GUIDs."

So how do we get around this? I started exploring how the data was stored by calling the Azure Search API directly. What I found was the multilist guid fields are stored in the following fashion.

"category_sm": [
  "efc89afd55e04000bbbad30960d4ecb3",
  "ace388700f904d529268219dfa35b55d"
]

The special characters are stripped out of the guid. With this known, here is my workaround.

string id = categoryIncludeItem.ID.ToString();
id = id.Replace("{", "");
id = id.Replace("}", "");
id = id.Replace("-", "");
categoryIncludePredicate = categoryIncludePredicate.And(item => item["category_sm"].Contains(id.ToLower()));

By normalizing the guid string, I am able to search. Not ideal and I would love to hear if anyone has a better solution, but this works.