ES|QL in the .NET client
This page helps you understand and use ES|QL in the .NET client.
The recommended way to work with ES|QL is the LINQ to ES|QL provider, which lets you write type-safe C# LINQ queries that are automatically translated to ES|QL at runtime.
For lower-level control, you can also use the Elasticsearch ES|QL API directly: This is the most flexible approach, but it's also the most complex because you must handle results in their raw form.
You can choose the precise format of results, such as JSON, CSV, or text.
The ES|QL query API allows you to specify how results should be returned. You can choose a response format such as CSV, text, or JSON, then fine-tune it with parameters like column separators and locale.
The following example gets ES|QL results as CSV and parses them:
var response = await client.Esql.QueryAsync(r => r
.Query("FROM index")
.Format("csv")
);
var csvContents = Encoding.UTF8.GetString(response.Data);
The previous example showed that although the raw ES|QL API offers maximum flexibility, additional work is required to use the result data.
The recommended approach is LINQ to ES|QL, which provides type-safe queries with automatic result mapping. Refer to the LINQ to ES|QL documentation for details.