使用关键字在azure搜索索引中查找文档



有一个例子(https://learn.microsoft.com/en-us/rest/api/searchservice/lookup-document#example)关于如何通过传递键值在azure搜索索引中搜索文档。我想使用Azure.NET SDK做同样的事情。有没有办法通过Azure.NET SDK做到这一点?我知道,如果我们在索引中搜索密钥,那么通过Azure.NET SDK可以实现这一点。但在我的情况下,我不应该让密钥可搜索。

我想你可以在下面找到你想要的东西。ISearchIndexClient.Documents属性上有一个Get方法,它完成了这项工作。

var searchClient = new SearchIndexClient(serviceName, indexName, new SearchCredentials(queryApiKey));
var document = searchClient.Documents.Get<YourDocument>(id);

您需要用Key属性标记您的Id。这是最低要求。请记住公共设置者。否则,文档将不会反序列化。

public class YourDocument
{
[System.ComponentModel.DataAnnotations.Key]
public string Id { get; set; }
}

最新更新