SearchClient.GetDocument<T> Method

Definition

Retrieves a document from Azure Cognitive Search. This is useful when a user clicks on a specific search result, and you want to look up specific details about that document. You can only get one document at a time. Use Search to get multiple documents in a single request. Lookup Document

public virtual Azure.Response<T> GetDocument<T> (string key, Azure.Search.Documents.GetDocumentOptions options = default, System.Threading.CancellationToken cancellationToken = default);
abstract member GetDocument : string * Azure.Search.Documents.GetDocumentOptions * System.Threading.CancellationToken -> Azure.Response<'T>
override this.GetDocument : string * Azure.Search.Documents.GetDocumentOptions * System.Threading.CancellationToken -> Azure.Response<'T>
Public Overridable Function GetDocument(Of T) (key As String, Optional options As GetDocumentOptions = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Response(Of T)

Type Parameters

T

The .NET type that maps to the index schema. Instances of this type can be retrieved as documents from the index.

Parameters

key
String

Required. An string value that uniquely identifies each document in the index. The key is sometimes referred to as a document ID. See Naming rules for the rules for constructing valid document keys.

options
GetDocumentOptions

Options to customize the operation's behavior.

cancellationToken
CancellationToken

Optional CancellationToken to propagate notifications that the operation should be canceled.

Returns

The document corresponding to the key.

Exceptions

Thrown when a failure is returned by the Search Service.

Remarks

The generic overloads of the GetDocument<T>(String, GetDocumentOptions, CancellationToken) and GetDocumentAsync<T>(String, GetDocumentOptions, CancellationToken) methods support mapping of Azure Search field types to .NET types via the type parameter T. Note that all search field types except collections are nullable, so we recommend using nullable types for the properties of T. See GetDocumentAsync<T>(String, GetDocumentOptions, CancellationToken) for more information.

Applies to