【发布时间】:2021-11-25 02:24:27
【问题描述】:
在 Microsoft Azure Search 上调用 Create 时,Search Service Client Indexes 会引发异常。 例外是:“请求无效”。 这是使用 .Net Core 3.1 的 C# 控制台应用程序。 网络上没有太多关于这个的讨论。 我做错了什么?
class Program
{
private static readonly string searchServiceName = "mysearchservice";
private static readonly string adminApiKey = "<<admin key here>>";
static void Main(string[] args)
{
var serviceClient = CreateSearchServiceClient();
CreateIndex(serviceClient);
}
private static void CreateIndex(SearchServiceClient ssc)
{
var definition = new Microsoft.Azure.Search.Models.Index()
{
Name = "hotels",
Fields = FieldBuilder.BuildForType<Hotel>()
};
ssc.Indexes.Create(definition); // Throws
}
private static SearchServiceClient CreateSearchServiceClient()
{
SearchServiceClient serviceClient =
new SearchServiceClient(searchServiceName,
new SearchCredentials(adminApiKey));
return serviceClient;
}
}
public class Hotel
{
[System.ComponentModel.DataAnnotations.Key]
[IsFilterable]
public string HotelId { get; set; }
[IsSearchable, IsSortable]
public string HotelName { get; set; }
[IsSearchable]
[Analyzer(AnalyzerName.AsString.EnLucene)]
public string Description { get; set; }
[IsSearchable, IsFilterable, IsSortable, IsFacetable]
public string Category { get; set; }
[IsSearchable, IsFilterable, IsFacetable]
public string[] Tags { get; set; }
[IsSearchable, IsSortable, IsFacetable]
public bool? ParkingIncluded { get; set; }
public DateTimeOffset? LastRenovationDate { get; set; }
[IsFilterable,IsSortable,IsFacetable]
public double? Rating { get; set; }
[IsFilterable, IsSortable]
public GeographyPoint Location { get; set; }
}
【问题讨论】: