how to use any/all filter using javascript on azure search

youssef125 271 Reputation points
2022-06-07T16:41:32.8+00:00

I'm trying to filter a collection on azure search using javascript :
here's the index :

![209231-image.png]1
here's javascript code :

const createFilterExpression = (filterList, facets) => {

let i = 0;

let filterExpressions = [];

while (i < filterList.length) {

let field = filterList[i].field;  

let value = filterList[i].value;  

if (facets[field] === 'array') {  

    filterExpressions.push(`${field}/any(t: search.in(t, '${value}', ','))`);  

} else {  

    filterExpressions.push(`${field} eq '${value}'`);  

}  

i += 1;  

}

return filterExpressions.join(' and ');

}

here's the postman body request:

{"q":"*","top":8,"skip":0,"filters":[{"field": "perfumers/name", "value": "Alpha Aromatics (USA)"}]}

but when I call the API I got this error :

"message": "Invalid expression: The parent value for a property access of a property 'name' is not a single value. Property access can only be applied to a single value.\r\nParameter name: $filter"
is there something wrong on the filter sent on the body.??

Azure AI Search
Azure AI Search
An Azure search service with built-in artificial intelligence capabilities that enrich information to help identify and explore relevant content at scale.
1,339 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. ajkuma 28,036 Reputation points Microsoft Employee Moderator
    2022-06-08T20:56:21.797+00:00

    youssef125-3012, Thanks for your question. As I understand, you're looking to search across multiple Edm.String fields in Collection(Edm.ComplexType) | matching child item.
    If I have misunderstood your ask, please do share more details about your specific requirement.

    Because the granularity of your index is at the parent level rather than the child level, currently it is not possible pull only the child item from the list.
    Alternatively, you could change the granularity of your index. Another option could be to keep your existing schema and then do a second layer of filtering of the */child at the application layer, to have only required criteria to list in your application.

    Quoting the response from Derek Legenzoff (from our Azure Search PG).
    "We don't have any immediate plans to change the way this works that I'm aware of but we're always looking to improve the product based on feedback from customers like yourself so we appreciate you sharing the feedback with us."

    Kindly check this thread for similar feedback request, response from our PG and workaround that you could leverage:

    FEATURE REQ Azure Search Working with Complex Collections

    Also checkout this doc - Model complex data types in Azure Cognitive Search] for more info.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.