Skip to content

Commit 9799f1d

Browse files
committed
Adding some YAML Rest tests.
1 parent 696a650 commit 9799f1d

File tree

1 file changed

+219
-0
lines changed

1 file changed

+219
-0
lines changed
Lines changed: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
setup:
2+
- requires:
3+
capabilities:
4+
- method: POST
5+
path: /_search
6+
capabilities: [ kql_query ]
7+
test_runner_features: capabilities
8+
reason: KQL query is not available
9+
10+
- requires:
11+
"test_runner_features": "contains"
12+
13+
- do:
14+
indices.create:
15+
index: test-index
16+
body:
17+
mappings:
18+
properties:
19+
department:
20+
type: keyword
21+
staff:
22+
type: integer
23+
courses:
24+
type: nested
25+
properties:
26+
name:
27+
type: text
28+
credits:
29+
type: integer
30+
sessions:
31+
type: nested
32+
properties:
33+
semester:
34+
type: keyword
35+
students:
36+
type: integer
37+
38+
- do:
39+
bulk:
40+
index: test-index
41+
refresh: true
42+
body: |
43+
{ "index" : { "_id": "doc-1" } }
44+
{ "department": "compsci", "staff": 12, "courses": [ { "name": "Object Oriented Programming", "credits": 3, "sessions": [ { "semester": "spr2021", "students": 37 }, { "semester": "fall2020", "students": 45} ] }, { "name": "Theory of Computation", "credits": 4, "sessions": [ { "semester": "spr2021", "students": 19 }, { "semester": "fall2020", "students": 14 } ] } ] }
45+
{ "index" : { "_id": "doc-42" } }
46+
{ "department": "math", "staff": 20, "courses": [ { "name": "Precalculus", "credits": 1, "sessions": [ { "semester": "spr2021", "students": 100 }, { "semester": "fall2020", "students": 134 } ] }, { "name": "Linear Algebra", "credits": 3, "sessions": [ { "semester": "spr2021", "students": 29 }, { "semester": "fall2020", "students": 23 } ] } ] }
47+
48+
---
49+
"Inline syntax":
50+
- do:
51+
search:
52+
index: test-index
53+
rest_total_hits_as_int: true
54+
body: >
55+
{
56+
"query": {
57+
"kql": {
58+
"query": "courses.name: object oriented programming"
59+
}
60+
}
61+
}
62+
- match: { hits.total: 1 }
63+
- match: { hits.hits.0._id: "doc-1" }
64+
65+
- do:
66+
search:
67+
index: test-index
68+
rest_total_hits_as_int: true
69+
body: >
70+
{
71+
"query": {
72+
"kql": {
73+
"query": "courses.name: object oriented programming AND courses.credits > 3"
74+
}
75+
}
76+
}
77+
- match: { hits.total: 1 }
78+
- match: { hits.hits.0._id: "doc-1" }
79+
80+
- do:
81+
search:
82+
index: test-index
83+
rest_total_hits_as_int: true
84+
body: >
85+
{
86+
"query": {
87+
"kql": {
88+
"query": "courses.name: object oriented programming OR courses.credits > 3"
89+
}
90+
}
91+
}
92+
- match: { hits.total: 1 }
93+
- match: { hits.hits.0._id: "doc-1" }
94+
95+
96+
---
97+
"Nested field syntax":
98+
- do:
99+
search:
100+
index: test-index
101+
rest_total_hits_as_int: true
102+
body: >
103+
{
104+
"query": {
105+
"kql": {
106+
"query": "courses : { name: object oriented programming }"
107+
}
108+
}
109+
}
110+
- match: { hits.total: 1 }
111+
- match: { hits.hits.0._id: "doc-1" }
112+
113+
- do:
114+
search:
115+
index: test-index
116+
rest_total_hits_as_int: true
117+
body: >
118+
{
119+
"query": {
120+
"kql": {
121+
"query": "courses: { name: object oriented programming AND credits > 3 }"
122+
}
123+
}
124+
}
125+
- match: { hits.total: 0 }
126+
127+
- do:
128+
search:
129+
index: test-index
130+
rest_total_hits_as_int: true
131+
body: >
132+
{
133+
"query": {
134+
"kql": {
135+
"query": "courses: { name: object oriented programming AND credits >= 3 }"
136+
}
137+
}
138+
}
139+
- match: { hits.total: 1 }
140+
- match: { hits.hits.0._id: "doc-1" }
141+
142+
- do:
143+
search:
144+
index: test-index
145+
rest_total_hits_as_int: true
146+
body: >
147+
{
148+
"query": {
149+
"kql": {
150+
"query": "courses: { name: object oriented programming OR credits > 3 }"
151+
}
152+
}
153+
}
154+
- match: { hits.total: 1 }
155+
- match: { hits.hits.0._id: "doc-1" }
156+
157+
- do:
158+
search:
159+
index: test-index
160+
rest_total_hits_as_int: true
161+
body: >
162+
{
163+
"query": {
164+
"kql": {
165+
"query": "courses: { NOT name: object oriented programming AND credits < 4 }"
166+
}
167+
}
168+
}
169+
- match: { hits.total: 1 }
170+
- match: { hits.hits.0._id: "doc-42" }
171+
172+
173+
---
174+
"Several level of nesting field syntax":
175+
- do:
176+
search:
177+
index: test-index
178+
rest_total_hits_as_int: true
179+
body: >
180+
{
181+
"query": {
182+
"kql": {
183+
"query": "courses: { name: object oriented programming AND sessions.semester: spr2021 }"
184+
}
185+
}
186+
}
187+
- match: { hits.total: 1 }
188+
- match: { hits.hits.0._id: "doc-1" }
189+
190+
191+
- do:
192+
search:
193+
index: test-index
194+
rest_total_hits_as_int: true
195+
body: >
196+
{
197+
"query": {
198+
"kql": {
199+
"query": "courses: { sessions : { semester: spr2021 AND students < 20 } }"
200+
}
201+
}
202+
}
203+
- match: { hits.total: 1 }
204+
- match: { hits.hits.0._id: "doc-1" }
205+
206+
- do:
207+
search:
208+
index: test-index
209+
rest_total_hits_as_int: true
210+
body: >
211+
{
212+
"query": {
213+
"kql": {
214+
"query": "courses: { name: computation AND sessions : { semester: spr2021 AND students < 20 } }"
215+
}
216+
}
217+
}
218+
- match: { hits.total: 1 }
219+
- match: { hits.hits.0._id: "doc-1" }

0 commit comments

Comments
 (0)