IDocumentOperations.GetAsync Method

 

Applies To: Microsoft Azure

Namespace:   Microsoft.Azure.Search
Assembly:  Microsoft.Azure.Search (in Microsoft.Azure.Search.dll)

Overload List

Name Description
System_CAPS_pubmethod GetAsync(String, IEnumerable<String>, CancellationToken)

Retrieves a document from the Azure Search index. (see https://msdn.microsoft.com/library/azure/dn798929.aspx for more information)

System_CAPS_pubmethod GetAsync<T>(String, IEnumerable<String>, CancellationToken)

Retrieves a document from the Azure Search index. (see https://msdn.microsoft.com/library/azure/dn798929.aspx for more information)

See Also

IDocumentOperations Interface
Microsoft.Azure.Search Namespace

Return to top

IDocumentOperations.GetAsync Method (String, IEnumerable<String>, CancellationToken)

Retrieves a document from the Azure Search index. (see https://msdn.microsoft.com/library/azure/dn798929.aspx for more information)

Syntax

Task<DocumentGetResponse> GetAsync(
    string key,
    IEnumerable<string> selectedFields,
    CancellationToken cancellationToken
)
Task<DocumentGetResponse^>^ GetAsync(
    String^ key,
    IEnumerable<String^>^ selectedFields,
    CancellationToken cancellationToken
)
abstract GetAsync : 
        key:string *
        selectedFields:IEnumerable<string> *
        cancellationToken:CancellationToken -> Task<DocumentGetResponse>
Function GetAsync (
    key As String,
    selectedFields As IEnumerable(Of String),
    cancellationToken As CancellationToken
) As Task(Of DocumentGetResponse)

Parameters

Return Value

Type: System.Threading.Tasks.Task<DocumentGetResponse>

Response containing the document.

Remarks

The non-generic overloads of the Get and GetAsync methods make a best-effort attempt to map JSON types in the response payload to .NET types. This mapping does not have the benefit of precise type information from the index, so the mapping is not always correct. In particular, be aware of the following cases:

  • Any numeric value without a decimal point will be deserialized to System.Int64 (long in C#).

  • Special double-precision floating point values such as NaN and Infinity will be deserialized as type System.String rather than System.Double.

  • Any string field with a value formatted like a DateTimeOffset will be deserialized incorrectly. We recommend storing such values in Edm.DateTimeOffset fields rather than Edm.String fields.

  • Any Edm.DateTimeOffset field will be deserialized as a System.DateTimeOffset, not System.DateTime.

Return to top

IDocumentOperations.GetAsync<T> Method (String, IEnumerable<String>, CancellationToken)

Retrieves a document from the Azure Search index. (see https://msdn.microsoft.com/library/azure/dn798929.aspx for more information)

Syntax

Task<DocumentGetResponse<T>> GetAsync<T>(
    string key,
    IEnumerable<string> selectedFields,
    CancellationToken cancellationToken
)
where T : class
generic<typename T>
where T : ref class
Task<DocumentGetResponse<T>^>^ GetAsync(
    String^ key,
    IEnumerable<String^>^ selectedFields,
    CancellationToken cancellationToken
)
abstract GetAsync<'T when 'T : not struct> : 
        key:string *
        selectedFields:IEnumerable<string> *
        cancellationToken:CancellationToken -> Task<DocumentGetResponse<'T>>
Function GetAsync(Of T As Class) (
    key As String,
    selectedFields As IEnumerable(Of String),
    cancellationToken As CancellationToken
) As Task(Of DocumentGetResponse(Of T))

Parameters

  • selectedFields
    Type: System.Collections.Generic.IEnumerable<String>

    List of field names to retrieve for the document; Any field not retrieved will have null or default as its corresponding property value in the returned object.

Return Value

Type: System.Threading.Tasks.Task<DocumentGetResponse<T>>

Response containing the document.

Type Parameters

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

Remarks

The generic overloads of the Get and GetAsync methods support mapping of Azure Search field types to .NET types via the type parameter T. Note that most Azure Search field types are nullable, so for primitives they often map to nullable types. The type mapping is as follows:

Azure Search field type

.NET type

Edm.String

System.String (string in C#)

Collection(Edm.String)

IEnumerable<System.String>

Edm.Boolean

System.Nullable<System.Boolean> (bool? in C#)

Edm.Double

System.Nullable<System.Double> (double? in C#)

Edm.Int32

System.Nullable<System.Int32> (int? in C#)

Edm.Int64

System.Nullable<System.Int64> (long? in C#)

Edm.DateTimeOffset

System.Nullable<System.DateTimeOffset> (DateTimeOffset? in C#) or System.Nullable<System.DateTime> (DateTime? in C#). Both types work, although we recommend using DateTimeOffset. When retrieving documents, DateTime values will always be in UTC. When indexing documents, DateTime values are interpreted as follows:

UTC DateTime

Sent as-is to the index.

Local DateTime

Converted to UTC before being sent to the index.

DateTime with unspecified time zone

Assumed to be UTC and sent as-is to the index.

Edm.GeographyPoint

Microsoft.Spatial.GeographyPoint

Return to top