【问题标题】:Lookup document in azure search index using the key使用键在 Azure 搜索索引中查找文档
【发布时间】:2019-05-14 22:56:28
【问题描述】:

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

【问题讨论】:

    标签: c# azure azure-cognitive-search azure-sdk-.net azure-search-.net-sdk


    【解决方案1】:

    我想你可以在下面找到你要找的东西。 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; }
    }
    

    【讨论】:

      猜你喜欢
      • 2021-03-21
      • 2016-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-05
      • 2016-12-12
      • 1970-01-01
      相关资源
      最近更新 更多