I am submitting a basic query to my index and then using data from the returned results to further filter that result set using the $filter
parameter and the search.in
function. However, when I apply the filter, it subsequently returns 0 results when I would expect it to return a subset of the original result set. I am able to reproduce this issue using the Search Explorer tool in the Azure Search portal.
My initial query is:
search=ski
... my subsequent filter is ...
search=ski&$filter=search.in(categories,'Ski Resorts','|')
Initial query returns a bunch of results, many of which have Ski Resorts
in the categories field. The second query returns no results.
In the index definition, the categories field is defined as an Edm.String field and searchable, filterable, retrievable and facetable. It contains a comma-separated list of categories for the document. My goal is to leverage these categories to allow users to further filter the result set.
Anyone know if I am using the search.in parameter incorrectly? I am going to experiment with other methods for achieving my outcome but curious what might not be right here.
Not surprisingly it was operator error but I definitely learned a good bit.
First, my goal is to allow users to filter down to categories they want. My index field could contain multiple values and I was originally trying to implement it with:
$filter=search.in(categories,pipeDelimitedTags,'|')
where the categories
field contains a comma-delimited list of category tags.
However, that expression assumes there is only a single value in the categories
field.
I updated my index and added a string collection and updated my query expression to:
$filter=categoriesCollection/any(c: search.in(c,pipeDelimitedTags,'|'))
Now my filter expression appears to be working!
In summary, two key changes:
Collection(Edm.String)
any
operator with the search.in
functionFor reference, OData Collection operators in Azure Cognitive Search
Thank you for the pointers!