There is this example (https://docs.microsoft.com/en-us/rest/api/searchservice/lookup-document#example) on how to search a document in the azure search index by passing in the key value. I want to do the same thing using Azure .NET SDK. Is there a way to do this through Azure .NET SDK? I know this is possible through Azure.NET SDK if we make the key searchable in the index. But in my case I am not supposed to make the key searchable.
1 Answers
3
votes
I think you can find below what you were looking for. There is a Get
method on ISearchIndexClient.Documents
property, which does the job.
var searchClient = new SearchIndexClient(serviceName, indexName, new SearchCredentials(queryApiKey));
var document = searchClient.Documents.Get<YourDocument>(id);
And you need to mark your Id
with Key
attribute. This is the minimum required. Please remember about public setters. Otherwise, the document won't deserialize.
public class YourDocument
{
[System.ComponentModel.DataAnnotations.Key]
public string Id { get; set; }
}