Skip to content

Commit 27bf417

Browse files
show ES|QL in all docs examples
1 parent 1f783d2 commit 27bf417

File tree

1 file changed

+42
-16
lines changed

1 file changed

+42
-16
lines changed

docs/reference/esql-query-builder.md

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,9 @@ The response body contains a `columns` attribute with the list of columns includ
4444
{'name': 'height_cm', 'type': 'double'}],
4545
'is_partial': False,
4646
'took': 11,
47-
'values': [['Adrian',
48-
'Wells',
49-
2.424,
50-
7.953144,
51-
242.4],
52-
['Aaron',
53-
'Gonzalez',
54-
1.584,
55-
5.1971,
56-
158.4],
57-
['Miranda',
58-
'Kramer',
59-
1.55,
60-
5.08555,
61-
155]]}
47+
'values': [['Adrian', 'Wells', 2.424, 7.953144, 242.4],
48+
['Aaron', 'Gonzalez', 1.584, 5.1971, 158.4],
49+
['Miranda', 'Kramer', 1.55, 5.08555, 155]]}
6250
```
6351

6452
## Creating an ES|QL query
@@ -74,10 +62,19 @@ Examples:
7462
```python
7563
from elasticsearch.esql import ESQL
7664

65+
# FROM employees
7766
query1 = ESQL.from_("employees")
67+
68+
# FROM <logs-{now/d}>
7869
query2 = ESQL.from_("<logs-{now/d}>")
70+
71+
# FROM employees-00001, other-employees-*
7972
query3 = ESQL.from_("employees-00001", "other-employees-*")
73+
74+
# FROM cluster_one:employees-00001, cluster_two:other-employees-*
8075
query4 = ESQL.from_("cluster_one:employees-00001", "cluster_two:other-employees-*")
76+
77+
# FROM employees METADATA _id
8178
query5 = ESQL.from_("employees").metadata("_id")
8279
```
8380

@@ -92,8 +89,13 @@ Examples:
9289
```python
9390
from elasticsearch.esql import ESQL, functions
9491

92+
# ROW a = 1, b = "two", c = null
9593
query1 = ESQL.row(a=1, b="two", c=None)
94+
95+
# ROW a = [1, 2]
9696
query2 = ESQL.row(a=[1, 2])
97+
98+
# ROW a = ROUND(1.23, 0)
9799
query3 = ESQL.row(a=functions.round(1.23, 0))
98100
```
99101

@@ -106,6 +108,7 @@ Example:
106108
```python
107109
from elasticsearch.esql import ESQL
108110

111+
# SHOW INFO
109112
query = ESQL.show("INFO")
110113
```
111114

@@ -118,6 +121,9 @@ results:
118121
```python
119122
from elasticsearch.esql import ESQL
120123

124+
# FROM employees
125+
# | WHERE still_hired == true
126+
# | LIMIT 10
121127
query = ESQL.from_("employees").where("still_hired == true").limit(10)
122128
```
123129

@@ -132,6 +138,10 @@ The simplest option is to provide all ES|QL expressions and conditionals as stri
132138
```python
133139
from elasticsearch.esql import ESQL
134140

141+
# FROM employees
142+
# | SORT emp_no
143+
# | KEEP first_name, last_name, height
144+
# | EVAL height_feet = height * 3.281, height_cm = height * 100
135145
query = (
136146
ESQL.from_("employees")
137147
.sort("emp_no")
@@ -145,6 +155,10 @@ A more advanced alternative is to replace the strings with Python expressions, w
145155
```python
146156
from elasticsearch.esql import ESQL, E
147157

158+
# FROM employees
159+
# | SORT emp_no
160+
# | KEEP first_name, last_name, height
161+
# | EVAL height_feet = height * 3.281, height_cm = height * 100
148162
query = (
149163
ESQL.from_("employees")
150164
.sort("emp_no")
@@ -158,8 +172,11 @@ Here the `E()` helper function is used as a wrapper to the column name that init
158172
Here is a second example, which uses a conditional expression in the `WHERE` command:
159173

160174
```python
161-
from elasticsearch.esql import ESQL, E
175+
from elasticsearch.esql import ESQL
162176

177+
# FROM employees
178+
# | KEEP first_name, last_name, height
179+
# | WHERE first_name == "Larry"
163180
query = (
164181
ESQL.from_("employees")
165182
.keep("first_name", "last_name", "height")
@@ -172,6 +189,9 @@ Using Python syntax, the condition can be rewritten as follows:
172189
```python
173190
from elasticsearch.esql import ESQL, E
174191

192+
# FROM employees
193+
# | KEEP first_name, last_name, height
194+
# | WHERE first_name == "Larry"
175195
query = (
176196
ESQL.from_("employees")
177197
.keep("first_name", "last_name", "height")
@@ -186,6 +206,9 @@ The ES|QL language includes a rich set of functions that can be used in expressi
186206
```python
187207
from elasticsearch.esql import ESQL
188208

209+
# FROM employees
210+
# | KEEP first_name, last_name, height
211+
# | WHERE LENGTH(first_name) < 4"
189212
query = (
190213
ESQL.from_("employees")
191214
.keep("first_name", "last_name", "height")
@@ -198,6 +221,9 @@ All available ES|QL functions have Python wrappers in the `elasticsearch.esql.fu
198221
```python
199222
from elasticsearch.esql import ESQL, functions
200223

224+
# FROM employees
225+
# | KEEP first_name, last_name, height
226+
# | WHERE LENGTH(first_name) < 4"
201227
query = (
202228
ESQL.from_("employees")
203229
.keep("first_name", "last_name", "height")

0 commit comments

Comments
 (0)