Search code examples
azurelambdaazure-cognitive-searchazure-search-.net-sdk

Query / Filter Azure Search Edm.Collection by any of multiple strings


I'm trying to filter an azure search edm.collection to return results if any of multiple strings are in the collection. I can only get it working when querying for one item, which isn't good enough for my use case. I can't find syntax for querying multiple parameters.

filter += "FirmTypes / any (x: x eq 'Big 4')";

the above works and returns all of the documents where firm type is Big 4.

I've tried multiple ways (some below) to filter for more than one parameter with no success

//filter += " OR any (x: x eq 'Industry')";
//filter += "FirmTypes / any (x: x eq 'Industry')";
//filter += "FirmTypes / any (x: x eq 'Big 4', 'Industry', 'PLC')"
//filter += "FirmTypes / any (x: x eq 'Big 4' or 'Industry' or 'PLC')"
//filter += "FirmTypes / any (x: x eq 'Big 4') or (x: x eq 'Industry')"
//filter += "FirmTypes / any (x: x eq 'Big 4')|(x: x eq 'Industry')"

Can anybody kindly point me in the right direction? Thank you in advance.


Solution

  • The best way to filter over multiple values is to use the new search.in function:

    FirmTypes/any(x: search.in(x, 'Big 4|Industry', '|'))
    

    For large numbers of values, search.in is significantly faster than using a combination of or and eq, and it can handle a much larger number of values without hitting the hard limits on filter complexity.