How do I utilize all the OData functions in the $filters parameter in azure cognitive search?

SAMANVITH M S 0 Reputation points
2023-04-06T05:03:24.0266667+00:00

I am trying to apply filters in azure cognitive search. I am finding it difficult to apply further advanced filters such as using dayOfWeek() . For example

$filter=TimeSlots/any(dt: contains(isof(dt, 'Edm.String'), 'Mon')) 
or
$filter=TimeSlots/any(dt: dayOfWeek(dt) eq 0) //to find if the date is a Sunday

I always seem to get an error when i try these types of queries in the azure search. I also can't use the "contains" function with the filters. "Invalid expression: No function signature for the function with name 'contains' matches the specified arguments. The function signatures considered are: contains(Edm.String Nullable=true, Edm.String Nullable=true).\r\nParameter name: $filter" I have tried looking at a few documentations and found that OData V4 is being used in azure search but these are not supported in that version. So how do I accomplish the results that I want

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,353 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Grmacjon-MSFT 19,301 Reputation points Moderator
    2023-04-12T20:39:38.66+00:00

    Hi @SAMANVITH M S You're getting this error "Invalid expression: No function signature for the function with name 'contains' matches the specified arguments." because Azure Cognitive Search supports a subset of the OData protocol, and not all functions are available. The dayOfWeek function is not supported in Azure Cognitive Search and the contains function are not supported in $filter expressions. You can learn more about Constants syntax in this Azure Document.   To apply advanced filters using OData functions in Azure Cognitive Search, you can use the search.in function. This function allows you to specify a list of values to match against a field. For example, if you have a field called DaysOfWeek that contains a comma-separated list of days (e.g., "Mon,Tue,Wed"), you can use the following filter expression to find documents that contain "Mon":

    $filter=search.in(DaysOfWeek, 'Mon', ',')
    

    This will return all documents where the DaysOfWeek field contains the value "Mon". Similarly, you can use the search.in function to filter documents based on multiple days:

    $filter=search.in(DaysOfWeek, 'Mon,Tue', ',')
    

    Keep in mind that the search.in function only works with string values, so you may need to convert your dates to strings before using this function. Also, the performance of the search may be affected by the complexity of the filter expressions. If you have a large dataset and complex filters, consider optimizing your search by using a more specific search schema, indexing only the necessary fields, and minimizing the number of filter expressions.   Hope that helps.   -Grace   If the information helped address your question, please "Accept" the answer. This will help us and also improve searchability for others in the community who might be researching similar information.

    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.