Skip to content

Latest commit

 

History

History
41 lines (31 loc) · 913 Bytes

File metadata and controls

41 lines (31 loc) · 913 Bytes
endpoint get_source
lang dotnet
es_version 9.3
client Elastic.Clients.Elasticsearch==9.3.0

Elasticsearch 9.3 get_source endpoint (.NET example)

Use client.GetSourceAsync<T>() to retrieve only the document body, without metadata.

var response = await client.GetSourceAsync<Product>("products", "prod-1");

if (response.IsValidResponse)
{
    Console.WriteLine($"{response.Name} — ${response.Price}");
}

Selecting fields

Use SourceIncludes to return a subset of fields:

var response = await client.GetSourceAsync<Product>("products", "prod-1",
    g => g.SourceIncludes(new[] { "name", "price" }));

Handling missing documents

Check IsValidResponse to handle missing documents:

var response = await client.GetSourceAsync<Product>("products", "prod-999");
if (!response.IsValidResponse)
{
    Console.WriteLine("Document not found");
}