|
| 1 | +[[esql]] |
| 2 | +== ES|QL in the .NET client |
| 3 | + |
| 4 | +This page helps you understand and use {ref}/esql.html[ES|QL] in the |
| 5 | +.NET client. |
| 6 | + |
| 7 | +There are two ways to use ES|QL in the .NET client: |
| 8 | + |
| 9 | +* Use the Elasticsearch {es-docs}/esql-apis.html[ES|QL API] directly: This |
| 10 | +is the most flexible approach, but it's also the most complex because you must handle |
| 11 | +results in their raw form. You can choose the precise format of results, |
| 12 | +such as JSON, CSV, or text. |
| 13 | +* Use ES|QL mapping helpers: These mappers take care of parsing the raw |
| 14 | +response into something readily usable by the application. Several mappers are |
| 15 | +available for different use cases, such as object mapping, cursor |
| 16 | +traversal of results, and dataframes. You can also define your own mapper for specific |
| 17 | +use cases. |
| 18 | + |
| 19 | + |
| 20 | + |
| 21 | +[discrete] |
| 22 | +[[esql-how-to]] |
| 23 | +==== How to use the ES|QL API |
| 24 | + |
| 25 | +The {es-docs}/esql-query-api.html[ES|QL query API] allows you to specify how |
| 26 | +results should be returned. You can choose a |
| 27 | +{es-docs}/esql-rest.html#esql-rest-format[response format] such as CSV, text, or |
| 28 | +JSON, then fine-tune it with parameters like column separators |
| 29 | +and locale. |
| 30 | + |
| 31 | +// Add any .NET-specific usage notes |
| 32 | + |
| 33 | +The following example gets ES|QL results as CSV and parses them: |
| 34 | + |
| 35 | +// Code example to be written |
| 36 | + |
| 37 | + |
| 38 | +[discrete] |
| 39 | +[[esql-consume-results]] |
| 40 | +==== Consume ES|QL results |
| 41 | + |
| 42 | +The previous example showed that although the raw ES|QL API offers maximum |
| 43 | +flexibility, additional work is required in order to make use of the |
| 44 | +result data. |
| 45 | + |
| 46 | +To simplify things, try working with these three main representations of ES|QL |
| 47 | +results (each with its own mapping helper): |
| 48 | + |
| 49 | +* **Objects**, where each row in the results is mapped to an object from your |
| 50 | +application domain. This is similar to what ORMs (object relational mappers) |
| 51 | +commonly do. |
| 52 | +* **Cursors**, where you scan the results row by row and access the data using |
| 53 | +column names. This is similar to database access libraries. |
| 54 | +* **Dataframes**, where results are organized in a column-oriented structure that |
| 55 | +allows efficient processing of column data. |
| 56 | + |
| 57 | +// Code examples to be written for each of them, depending on availability in the language |
| 58 | + |
| 59 | + |
| 60 | +[discrete] |
| 61 | +[[esql-custom-mapping]] |
| 62 | +==== Define your own mapping |
| 63 | + |
| 64 | +Although the mappers provided by the .NET client cover many use cases, your |
| 65 | +application might require a custom mapping. |
| 66 | +You can write your own mapper and use it in a similar way as the |
| 67 | +built-in ones. |
| 68 | + |
| 69 | +Note that mappers are meant to provide a more usable representation of ES|QL |
| 70 | +results—not to process the result data. Data processing should be based on |
| 71 | +the output of a result mapper. |
| 72 | + |
| 73 | +Here's an example mapper that returns a simple column-oriented |
| 74 | +representation of the data: |
| 75 | + |
| 76 | +// Code example to be written |
0 commit comments