@@ -44,21 +44,9 @@ The response body contains a `columns` attribute with the list of columns includ
44
44
{' name' : ' height_cm' , ' type' : ' double' }],
45
45
' is_partial' : False ,
46
46
' 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 ]]}
62
50
```
63
51
64
52
## Creating an ES|QL query
@@ -74,10 +62,19 @@ Examples:
74
62
``` python
75
63
from elasticsearch.esql import ESQL
76
64
65
+ # FROM employees
77
66
query1 = ESQL .from_(" employees" )
67
+
68
+ # FROM <logs-{now/d}>
78
69
query2 = ESQL .from_(" <logs-{now/d}>" )
70
+
71
+ # FROM employees-00001, other-employees-*
79
72
query3 = ESQL .from_(" employees-00001" , " other-employees-*" )
73
+
74
+ # FROM cluster_one:employees-00001, cluster_two:other-employees-*
80
75
query4 = ESQL .from_(" cluster_one:employees-00001" , " cluster_two:other-employees-*" )
76
+
77
+ # FROM employees METADATA _id
81
78
query5 = ESQL .from_(" employees" ).metadata(" _id" )
82
79
```
83
80
@@ -92,8 +89,13 @@ Examples:
92
89
``` python
93
90
from elasticsearch.esql import ESQL , functions
94
91
92
+ # ROW a = 1, b = "two", c = null
95
93
query1 = ESQL .row(a = 1 , b = " two" , c = None )
94
+
95
+ # ROW a = [1, 2]
96
96
query2 = ESQL .row(a = [1 , 2 ])
97
+
98
+ # ROW a = ROUND(1.23, 0)
97
99
query3 = ESQL .row(a = functions.round(1.23 , 0 ))
98
100
```
99
101
@@ -106,6 +108,7 @@ Example:
106
108
``` python
107
109
from elasticsearch.esql import ESQL
108
110
111
+ # SHOW INFO
109
112
query = ESQL .show(" INFO" )
110
113
```
111
114
@@ -118,6 +121,9 @@ results:
118
121
``` python
119
122
from elasticsearch.esql import ESQL
120
123
124
+ # FROM employees
125
+ # | WHERE still_hired == true
126
+ # | LIMIT 10
121
127
query = ESQL .from_(" employees" ).where(" still_hired == true" ).limit(10 )
122
128
```
123
129
@@ -132,6 +138,10 @@ The simplest option is to provide all ES|QL expressions and conditionals as stri
132
138
``` python
133
139
from elasticsearch.esql import ESQL
134
140
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
135
145
query = (
136
146
ESQL .from_(" employees" )
137
147
.sort(" emp_no" )
@@ -145,6 +155,10 @@ A more advanced alternative is to replace the strings with Python expressions, w
145
155
``` python
146
156
from elasticsearch.esql import ESQL , E
147
157
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
148
162
query = (
149
163
ESQL .from_(" employees" )
150
164
.sort(" emp_no" )
@@ -158,8 +172,11 @@ Here the `E()` helper function is used as a wrapper to the column name that init
158
172
Here is a second example, which uses a conditional expression in the ` WHERE ` command:
159
173
160
174
``` python
161
- from elasticsearch.esql import ESQL , E
175
+ from elasticsearch.esql import ESQL
162
176
177
+ # FROM employees
178
+ # | KEEP first_name, last_name, height
179
+ # | WHERE first_name == "Larry"
163
180
query = (
164
181
ESQL .from_(" employees" )
165
182
.keep(" first_name" , " last_name" , " height" )
@@ -172,6 +189,9 @@ Using Python syntax, the condition can be rewritten as follows:
172
189
``` python
173
190
from elasticsearch.esql import ESQL , E
174
191
192
+ # FROM employees
193
+ # | KEEP first_name, last_name, height
194
+ # | WHERE first_name == "Larry"
175
195
query = (
176
196
ESQL .from_(" employees" )
177
197
.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
186
206
``` python
187
207
from elasticsearch.esql import ESQL
188
208
209
+ # FROM employees
210
+ # | KEEP first_name, last_name, height
211
+ # | WHERE LENGTH(first_name) < 4"
189
212
query = (
190
213
ESQL .from_(" employees" )
191
214
.keep(" first_name" , " last_name" , " height" )
@@ -198,6 +221,9 @@ All available ES|QL functions have Python wrappers in the `elasticsearch.esql.fu
198
221
``` python
199
222
from elasticsearch.esql import ESQL , functions
200
223
224
+ # FROM employees
225
+ # | KEEP first_name, last_name, height
226
+ # | WHERE LENGTH(first_name) < 4"
201
227
query = (
202
228
ESQL .from_(" employees" )
203
229
.keep(" first_name" , " last_name" , " height" )
0 commit comments