我正在尝试在我的数据库表上学习 Azure AI 搜索。我有以下数据集。
我可以按如下方式进行搜索(Lucene)并且效果很好:
{
"queryType": "full",
"search": "Subject_Name:Math",
"count": true
}
但是当我按如下方式进行操作时,它会显示错误“无效搜索语法:对数字字段的搜索无效。仅允许在数字字段中搜索数字值。”
{
"queryType": "full",
"search": "Subject_Name:Math AND Marks:>10",
"count": true
}
参考资料:
当您进行查询搜索时,它仅在字符串字段中搜索,并且您还指定了要搜索的字段名称
Subject_Name
。但是 Math
在你的情况下是 double 或 int 。
因此,您需要对该字段进行过滤。
在字段上启用“可过滤”以对其进行过滤。
接下来,像下面这样查询。
{
"queryType": "full",
"search": "Subject_Name:Math",
"filter": "Marks gt 10",
"count": true
}
并输出样本数据。
{
"@odata.context": "https://xyz.search.windows.net/indexes('marks')/$metadata#docs(*)",
"@odata.count": 3,
"value": [
{
"@search.score": 0.6931472,
"Unique_Record_ID": 1507373411,
"Student_ID": 681046,
"Subject_Name": "Math",
"Marks": 42,
"Test_Date": "2023-08-23T00:00:00Z",
"Result_Reported_Date": "2023-08-23T00:00:00Z",
"ETLInsertTS": "2023-08-24T04:19:00Z",
"AzureSearch_DocumentKey": "aHR0cHM6Ly92amd2OzQ1"
},
{
"@search.score": 0.2876821,
"Unique_Record_ID": 152442821,
"Student_ID": 681046,
"Subject_Name": "Math",
"Marks": 48,
"Test_Date": "2023-12-06T00:00:00Z",
"Result_Reported_Date": "2023-12-06T00:00:00Z",
"ETLInsertTS": "2023-12-07T04:19:00Z",
"AzureSearch_DocumentKey": "aHR0cHM6Ly92amnMuY3N2OzM1"
},
{
"@search.score": 0.2876821,
"Unique_Record_ID": 1425813725,
"Student_ID": 681046,
"Subject_Name": "Math",
"Marks": 65,
"Test_Date": "2022-06-09T00:00:00Z",
"Result_Reported_Date": "2022-06-09T00:00:00Z",
"ETLInsertTS": "2022-06-10T04:17:00Z",
"AzureSearch_DocumentKey": "aHR0cHM6Ly92aRlcnMuY3N2OzU1"
}
]
}
接下来通过聚合来创建称为改进分数的新列以获得改进分数,因为ai搜索不支持此类操作。
然后您可以像下面一样过滤该字段。
{
"queryType": "full",
"search": "Subject_Name:Math",
"filter": "Score_Improvement ge 5",
"count": true
}