Skip to content

Commit 21a1572

Browse files
esql DSL tests
1 parent 2943c87 commit 21a1572

File tree

2 files changed

+188
-26
lines changed

2 files changed

+188
-26
lines changed

test_elasticsearch/test_dsl/test_integration/_async/test_esql.py

Lines changed: 94 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,13 @@
1717

1818
import pytest
1919

20-
from elasticsearch.dsl import AsyncDocument, E, M
21-
from elasticsearch.esql import ESQL, functions
20+
from elasticsearch.dsl import AsyncDocument, InnerDoc, M
21+
from elasticsearch.esql import ESQL, E, functions
22+
23+
24+
class Address(InnerDoc):
25+
address: M[str]
26+
city: M[str]
2227

2328

2429
class Employee(AsyncDocument):
@@ -27,31 +32,107 @@ class Employee(AsyncDocument):
2732
last_name: M[str]
2833
height: M[float]
2934
still_hired: M[bool]
35+
address: M[Address]
3036

3137
class Index:
3238
name = "employees"
3339

3440

3541
async def load_db():
3642
data = [
37-
[10000, "Joseph", "Wall", 2.2, True],
38-
[10001, "Stephanie", "Ward", 1.749, True],
39-
[10002, "David", "Keller", 1.872, True],
40-
[10003, "Roger", "Hinton", 1.694, False],
41-
[10004, "Joshua", "Garcia", 1.661, False],
42-
[10005, "Matthew", "Richards", 1.633, False],
43-
[10006, "Maria", "Luna", 1.893, True],
44-
[10007, "Angela", "Navarro", 1.604, False],
45-
[10008, "Maria", "Cannon", 2.079, False],
46-
[10009, "Joseph", "Sutton", 2.025, True],
43+
[
44+
10000,
45+
"Joseph",
46+
"Wall",
47+
2.2,
48+
True,
49+
Address(address="8875 Long Shoals Suite 441", city="Marcville, TX"),
50+
],
51+
[
52+
10001,
53+
"Stephanie",
54+
"Ward",
55+
1.749,
56+
True,
57+
Address(address="90162 Carter Harbor Suite 099", city="Davisborough, DE"),
58+
],
59+
[
60+
10002,
61+
"David",
62+
"Keller",
63+
1.872,
64+
True,
65+
Address(address="6697 Patrick Union Suite 797", city="Fuentesmouth, SD"),
66+
],
67+
[
68+
10003,
69+
"Roger",
70+
"Hinton",
71+
1.694,
72+
False,
73+
Address(address="809 Kelly Mountains", city="South Megan, DE"),
74+
],
75+
[
76+
10004,
77+
"Joshua",
78+
"Garcia",
79+
1.661,
80+
False,
81+
Address(address="718 Angela Forks", city="Port Erinland, MA"),
82+
],
83+
[
84+
10005,
85+
"Matthew",
86+
"Richards",
87+
1.633,
88+
False,
89+
Address(address="2869 Brown Mountains", city="New Debra, NH"),
90+
],
91+
[
92+
10006,
93+
"Maria",
94+
"Luna",
95+
1.893,
96+
True,
97+
Address(address="5861 Morgan Springs", city="Lake Daniel, WI"),
98+
],
99+
[
100+
10007,
101+
"Angela",
102+
"Navarro",
103+
1.604,
104+
False,
105+
Address(address="2848 Allen Station", city="Saint Joseph, OR"),
106+
],
107+
[
108+
10008,
109+
"Maria",
110+
"Cannon",
111+
2.079,
112+
False,
113+
Address(address="322 NW Johnston", city="Bakerburgh, MP"),
114+
],
115+
[
116+
10009,
117+
"Joseph",
118+
"Sutton",
119+
2.025,
120+
True,
121+
Address(address="77 Cardinal E", city="Lakestown, IL"),
122+
],
47123
]
48124
if await Employee._index.exists():
49125
await Employee._index.delete()
50126
await Employee.init()
51127

52128
for e in data:
53129
employee = Employee(
54-
emp_no=e[0], first_name=e[1], last_name=e[2], height=e[3], still_hired=e[4]
130+
emp_no=e[0],
131+
first_name=e[1],
132+
last_name=e[2],
133+
height=e[3],
134+
still_hired=e[4],
135+
address=e[5],
55136
)
56137
await employee.save()
57138
await Employee._index.refresh()

test_elasticsearch/test_dsl/test_integration/_sync/test_esql.py

Lines changed: 94 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,13 @@
1717

1818
import pytest
1919

20-
from elasticsearch.dsl import Document, E, M
21-
from elasticsearch.esql import ESQL, functions
20+
from elasticsearch.dsl import Document, InnerDoc, M
21+
from elasticsearch.esql import ESQL, E, functions
22+
23+
24+
class Address(InnerDoc):
25+
address: M[str]
26+
city: M[str]
2227

2328

2429
class Employee(Document):
@@ -27,31 +32,107 @@ class Employee(Document):
2732
last_name: M[str]
2833
height: M[float]
2934
still_hired: M[bool]
35+
address: M[Address]
3036

3137
class Index:
3238
name = "employees"
3339

3440

3541
def load_db():
3642
data = [
37-
[10000, "Joseph", "Wall", 2.2, True],
38-
[10001, "Stephanie", "Ward", 1.749, True],
39-
[10002, "David", "Keller", 1.872, True],
40-
[10003, "Roger", "Hinton", 1.694, False],
41-
[10004, "Joshua", "Garcia", 1.661, False],
42-
[10005, "Matthew", "Richards", 1.633, False],
43-
[10006, "Maria", "Luna", 1.893, True],
44-
[10007, "Angela", "Navarro", 1.604, False],
45-
[10008, "Maria", "Cannon", 2.079, False],
46-
[10009, "Joseph", "Sutton", 2.025, True],
43+
[
44+
10000,
45+
"Joseph",
46+
"Wall",
47+
2.2,
48+
True,
49+
Address(address="8875 Long Shoals Suite 441", city="Marcville, TX"),
50+
],
51+
[
52+
10001,
53+
"Stephanie",
54+
"Ward",
55+
1.749,
56+
True,
57+
Address(address="90162 Carter Harbor Suite 099", city="Davisborough, DE"),
58+
],
59+
[
60+
10002,
61+
"David",
62+
"Keller",
63+
1.872,
64+
True,
65+
Address(address="6697 Patrick Union Suite 797", city="Fuentesmouth, SD"),
66+
],
67+
[
68+
10003,
69+
"Roger",
70+
"Hinton",
71+
1.694,
72+
False,
73+
Address(address="809 Kelly Mountains", city="South Megan, DE"),
74+
],
75+
[
76+
10004,
77+
"Joshua",
78+
"Garcia",
79+
1.661,
80+
False,
81+
Address(address="718 Angela Forks", city="Port Erinland, MA"),
82+
],
83+
[
84+
10005,
85+
"Matthew",
86+
"Richards",
87+
1.633,
88+
False,
89+
Address(address="2869 Brown Mountains", city="New Debra, NH"),
90+
],
91+
[
92+
10006,
93+
"Maria",
94+
"Luna",
95+
1.893,
96+
True,
97+
Address(address="5861 Morgan Springs", city="Lake Daniel, WI"),
98+
],
99+
[
100+
10007,
101+
"Angela",
102+
"Navarro",
103+
1.604,
104+
False,
105+
Address(address="2848 Allen Station", city="Saint Joseph, OR"),
106+
],
107+
[
108+
10008,
109+
"Maria",
110+
"Cannon",
111+
2.079,
112+
False,
113+
Address(address="322 NW Johnston", city="Bakerburgh, MP"),
114+
],
115+
[
116+
10009,
117+
"Joseph",
118+
"Sutton",
119+
2.025,
120+
True,
121+
Address(address="77 Cardinal E", city="Lakestown, IL"),
122+
],
47123
]
48124
if Employee._index.exists():
49125
Employee._index.delete()
50126
Employee.init()
51127

52128
for e in data:
53129
employee = Employee(
54-
emp_no=e[0], first_name=e[1], last_name=e[2], height=e[3], still_hired=e[4]
130+
emp_no=e[0],
131+
first_name=e[1],
132+
last_name=e[2],
133+
height=e[3],
134+
still_hired=e[4],
135+
address=e[5],
55136
)
56137
employee.save()
57138
Employee._index.refresh()

0 commit comments

Comments
 (0)