| endpoint | get_source |
|---|---|
| lang | dotnet |
| es_version | 9.3 |
| client | Elastic.Clients.Elasticsearch==9.3.0 |
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}");
}Use SourceIncludes to return a subset of fields:
var response = await client.GetSourceAsync<Product>("products", "prod-1",
g => g.SourceIncludes(new[] { "name", "price" }));Check IsValidResponse to handle missing documents:
var response = await client.GetSourceAsync<Product>("products", "prod-999");
if (!response.IsValidResponse)
{
Console.WriteLine("Document not found");
}