在 Azure 搜索索引上的过滤不起作用。

huangapple go评论61阅读模式
英文:

Filtering on Azure Search Index not working

问题

问题 2:我的实际代码出现了以下两个错误(独立运行时出现),我已经尝试详细描述这两个错误,但没有真正进入代码。

问题 2.a

错误:() 无效表达式:检测到不兼容类型的二进制运算符。找到操作数类型为 'Edm.String' 和 'Edm.Int32' 的运算符类型 'Equal'

对于过滤参数 = 'max_tokens_in_chunk eq 200'
其中 max_tokens_in_chunk 是一个在搜索索引中创建的列,如下所示:SimpleField(name="max_tokens_in_chunk", type="Edm.String", filterable=True, facetable=True)

问题 2.b

错误:() 无效表达式:在类型 'search.document' 上找不到名为 'Tesla' 的属性。
参数名称:$filter
代码:
消息:无效表达式:在类型 'search.document' 上找不到名为 'Tesla' 的属性。
参数名称:$filter

对于过滤参数 = 'company eq Tesla'

'company' 是一个在搜索索引中创建的列,如下所示:SimpleField(name="company", type="Edm.String", filterable=True, facetable=True)。我可以保证 'Tesla' 存在,因为我从搜索索引中打印出了它。

英文:

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

答案1

得分: 1

关于2(a),您之所以收到此错误是因为字段数据类型为String,而您正在使用整数值进行筛选。如评论中所述,请使用以下筛选条件:

max_tokens_in_chunk eq '200'

关于2(b),我认为您之所以收到错误是因为您直接使用Tesla,搜索服务认为它是索引中的另一个字段。再次解决方法与上述类似:

company eq 'Tesla'
英文:

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'

huangapple
  • 本文由 发表于 2023年7月14日 03:55:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/76682830.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定