Search code examples
pythonazureazure-cognitive-servicesazure-cognitive-search

Filtering on Azure Search Index not working


Edit - Removed Issue 1 as I was using the wrong function

Issue 2: My actual code gives the 2 below errors (ran independently of each other) that I have tried to detail out without actually getting into the code

Issue 2.a

Error: () Invalid expression: A binary operator with incompatible types was detected. Found operand types 'Edm.String' and 'Edm.Int32' for operator kind 'Equal'  

for the filter arg = ''max_tokens_in_chunk eq 200'

where max_tokens_in_chunk is a column in the search index created as SimpleField(name="max_tokens_in_chunk", type="Edm.String", filterable=True, facetable=True)

Issue 2.b

Error: () Invalid expression: Could not find a property named 'Tesla' on type 'search.document'.
Parameter name: $filter
Code:
Message: Invalid expression: Could not find a property named 'Tesla' on type 'search.document'.
Parameter name: $filter

for the filter arg = 'company eq Tesla'

'where company is a column created as SimpleField(name="company", type="Edm.String", filterable=True, facetable=True) . I can gaurantee Tesla is present because I printed it out from the Search Index


Solution

  • Regarding 2(a), the reason you are getting this error is because the field data type is String and you are using an integer value for filtering. As mentioned in the comments, please use the following filtering criteria:

    max_tokens_in_chunk eq '200'
    

    Regarding 2(b), I believe the reason you are getting the error is because you are using Tesla as is and search service is thinking that it is another field in your index. Again the solution is similar to above:

    company eq 'Tesla'