diff --git a/docs/reference/esql.md b/docs/reference/esql.md index 6fea4bcdd9..0f2cb112b4 100644 --- a/docs/reference/esql.md +++ b/docs/reference/esql.md @@ -14,6 +14,7 @@ There are two ways to use ES|QL in the Ruby client: * Use the Elasticsearch [ES|QL API](https://www.elastic.co/docs/api/doc/elasticsearch/group/endpoint-esql) 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. * Use the Ruby ES|QL helper: The helper maps the raw response to an object that’s more readily usable by your application. +You can also try the [`elastic-esql`](#esql-ruby) gem, which helps you build ES|QL queries with Ruby. ## ES|QL API [esql-how-to] @@ -108,3 +109,24 @@ puts response {"duration_ms"=>8.3, "message"=>"Connection error", "event.duration"=>"8268153", "client.ip"=>#, "@timestamp"=>#} ``` +## ES|QL Query Builder [esql-ruby] + +The [`elastic-esql`](https://github.com/elastic/esql-ruby) gem helps you build queries for use with the [ES|QL query API](docs-content://explore-analyze/query-filter/languages/esql-rest.md). Here's an example: + +```ruby +query = Elastic::ESQL.from('sample') + .sort('@timestamp') + .desc + .where('event_duration > 5000000') + .limit(3) +``` + +You can see the generated query with `.to_s`: + +```ruby +query.to_s +=> "FROM sample | SORT @timestamp DESC | WHERE event_duration > 5000000 | LIMIT 3" +``` + +The `elastic-esql` library works independently of the {{es}} client, so you can use it alongside any client — not just `elasticsearch-ruby`. +For more information, see the gem [README](https://github.com/elastic/esql-ruby?tab=readme-ov-file#ruby-esql-query-builder).