Skip to content

Commit fe6d2b3

Browse files
committed
Move semantic text tests to a separate field
1 parent 3a8ef30 commit fe6d2b3

File tree

2 files changed

+278
-16
lines changed

2 files changed

+278
-16
lines changed
Lines changed: 278 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,278 @@
1+
testKnnWithSemanticText
2+
required_capability: knn_function_v4
3+
4+
from semantic_text
5+
| where knn(semantic_text_dense_field, [0, 1, 2], 10)
6+
| keep semantic_text_dense_field
7+
| sort semantic_text_dense_field asc
8+
;
9+
10+
semantic_text_dense_field:text
11+
all we have to decide is what to do with the time that is given to us
12+
be excellent to each other
13+
live long and prosper
14+
;
15+
16+
testKnnWithSemanticTextAndKeyword
17+
required_capability: knn_function_v4
18+
19+
from semantic_text
20+
| where knn(semantic_text_dense_field, [0, 1, 2], 10)
21+
| keep semantic_text_dense_field, host
22+
| sort host asc
23+
;
24+
25+
semantic_text_dense_field:text | host:keyword
26+
live long and prosper | host1
27+
all we have to decide is what to do with the time that is given to us | host2
28+
be excellent to each other | host3
29+
30+
;
31+
32+
testKnnWithSemanticTextMultiValueField
33+
required_capability: knn_function_v4
34+
35+
from semantic_text metadata _id
36+
| where match(st_multi_value, "something") AND match(host, "host1")
37+
| keep _id, st_multi_value
38+
;
39+
40+
_id: keyword | st_multi_value:text
41+
1 | ["Hello there!", "This is a random value", "for testing purposes"]
42+
;
43+
44+
testKnnWithSemanticTextWithEvalsAndOtherFunctionsAndStats
45+
required_capability: knn_function_v4
46+
47+
from semantic_text
48+
| where qstr("description:some*")
49+
| eval size = mv_count(st_multi_value)
50+
| where knn(semantic_text_dense_field, [0, 1, 2], 10)
51+
| STATS result = count(*)
52+
;
53+
54+
result:long
55+
3
56+
;
57+
58+
testKnnWithSemanticTextAndKql
59+
required_capability: knn_function_v4
60+
required_capability: kql_function
61+
62+
from semantic_text
63+
| where kql("host:host1") AND knn(semantic_text_dense_field, [0, 1, 2], 10)
64+
| KEEP host, semantic_text_dense_field
65+
;
66+
67+
host:keyword | semantic_text_dense_field:text
68+
"host1" | live long and prosper
69+
;
70+
71+
testKnnWithOptionsFuzziness
72+
required_capability: knn_function_v4
73+
required_capability: knn_function_v4_options
74+
75+
from books
76+
| where match(title, "Pings", {"fuzziness": 1})
77+
| keep book_no;
78+
ignoreOrder:true
79+
80+
book_no:keyword
81+
2714
82+
2675
83+
4023
84+
7140
85+
;
86+
87+
testKnnWithOptionsOperator
88+
required_capability: knn_function_v4
89+
required_capability: knn_function_v4_options
90+
91+
// tag::match-with-named-function-params[]
92+
FROM books
93+
| WHERE MATCH(title, "Hobbit Back Again", {"operator": "AND"})
94+
| KEEP title;
95+
// end::match-with-named-function-params[]
96+
97+
// tag::match-with-named-function-params-result[]
98+
title:text
99+
The Hobbit or There and Back Again
100+
// end::match-with-named-function-params-result[]
101+
;
102+
103+
testKnnWithOptionsMinimumShouldKnn
104+
required_capability: knn_function_v4
105+
required_capability: knn_function_v4_options
106+
107+
from books
108+
| where match(title, "Hobbit Back Again", {"minimum_should_match": 2})
109+
| keep title;
110+
111+
title:text
112+
The Hobbit or There and Back Again
113+
;
114+
115+
testKnnWithNonPushableDisjunctions
116+
required_capability: knn_function_v4
117+
required_capability: full_text_functions_disjunctions_compute_engine
118+
119+
from books
120+
| where match(title, "lord") or length(title) > 130
121+
| keep book_no
122+
;
123+
ignoreOrder: true
124+
125+
book_no:keyword
126+
2675
127+
2714
128+
4023
129+
7140
130+
8678
131+
;
132+
133+
testKnnWithNonPushableDisjunctionsOnComplexExpressions
134+
required_capability: knn_function_v4
135+
required_capability: full_text_functions_disjunctions_compute_engine
136+
137+
from books
138+
| where (match(title, "lord") and ratings > 4.5) or (match(author, "dostoevsky") and length(title) > 50)
139+
| keep book_no
140+
;
141+
ignoreOrder: true
142+
143+
book_no:keyword
144+
2675
145+
2924
146+
4023
147+
1937
148+
7140
149+
2714
150+
;
151+
152+
testKnnInStatsNonPushable
153+
required_capability: knn_function_v4
154+
required_capability: full_text_functions_in_stats_where
155+
156+
from books
157+
| where length(title) > 40
158+
| stats c = count(*) where match(title, "Lord")
159+
;
160+
161+
c:long
162+
3
163+
;
164+
165+
testKnnInStatsPushableAndNonPushable
166+
required_capability: knn_function_v4
167+
required_capability: full_text_functions_in_stats_where
168+
169+
from books
170+
| stats c = count(*) where (match(title, "lord") and ratings > 4.5) or (match(author, "dostoevsky") and length(title) > 50)
171+
;
172+
173+
c:long
174+
6
175+
;
176+
177+
testKnnInStatsPushable
178+
required_capability: knn_function_v4
179+
required_capability: full_text_functions_in_stats_where
180+
181+
from books
182+
| stats c = count(*) where match(author, "tolkien")
183+
;
184+
185+
c:long
186+
22
187+
;
188+
189+
testKnnInStatsWithOptions
190+
required_capability: knn_function_v4
191+
required_capability: full_text_functions_in_stats_where
192+
193+
FROM books
194+
| STATS c = count(*) where match(title, "Hobbit Back Again", {"operator": "AND"})
195+
;
196+
197+
c:long
198+
1
199+
;
200+
201+
testKnnInStatsWithNonPushableDisjunctions
202+
required_capability: knn_function_v4
203+
required_capability: full_text_functions_in_stats_where
204+
205+
FROM books
206+
| STATS c = count(*) where match(title, "lord") or length(title) > 130
207+
;
208+
209+
c:long
210+
5
211+
;
212+
213+
testKnnInStatsWithMultipleAggs
214+
required_capability: knn_function_v4
215+
required_capability: full_text_functions_in_stats_where
216+
FROM books
217+
| STATS c = count(*) where match(title, "lord"), m = max(book_no::integer) where match(author, "tolkien"), n = min(book_no::integer) where match(author, "dostoevsky")
218+
;
219+
220+
c:long | m:integer | n:integer
221+
4 | 9607 | 1211
222+
;
223+
224+
225+
testKnnInStatsWithGrouping
226+
required_capability: knn_function_v4
227+
required_capability: full_text_functions_in_stats_where
228+
FROM books
229+
| STATS r = AVG(ratings) where match(title, "Lord Rings", {"operator": "AND"}) by author | WHERE r is not null
230+
;
231+
ignoreOrder: true
232+
233+
r:double | author: text
234+
4.75 | Alan Lee
235+
4.674999952316284 | J. R. R. Tolkien
236+
4.670000076293945 | John Ronald Reuel Tolkien
237+
4.670000076293945 | Agnes Perkins
238+
4.670000076293945 | Charles Adolph Huttar
239+
4.670000076293945 | Walter Scheps
240+
4.559999942779541 | J.R.R. Tolkien
241+
;
242+
243+
testKnnInStatsWithGroupingBy
244+
required_capability: knn_function_v4
245+
required_capability: full_text_functions_in_stats_where
246+
FROM airports
247+
| STATS c = COUNT(*) where match(country, "United States") BY scalerank
248+
| SORT scalerank desc
249+
;
250+
251+
c: long | scalerank: long
252+
0 | 9
253+
44 | 8
254+
10 | 7
255+
28 | 6
256+
10 | 5
257+
12 | 4
258+
10 | 3
259+
15 | 2
260+
;
261+
262+
263+
testKnnWithReplace
264+
required_capability: knn_function_v4
265+
required_capability: no_plain_strings_in_literals
266+
from books
267+
| keep book_no, author
268+
| where match(author, REPLACE("FaulkneX", "X", "r"))
269+
| sort book_no
270+
| limit 5;
271+
272+
book_no:keyword | author:text
273+
2378 | [Carol Faulkner, Holly Byers Ochoa, Lucretia Mott]
274+
2713 | William Faulkner
275+
2847 | Colleen Faulkner
276+
2883 | William Faulkner
277+
3293 | Danny Faulkner
278+
;

x-pack/plugin/esql/qa/testFixtures/src/main/resources/knn-function.csv-spec

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -306,19 +306,3 @@ c: long | primary: boolean
306306
41 | false
307307
9 | true
308308
;
309-
310-
testKnnWithWithSemanticText
311-
required_capability: knn_function_v4
312-
required_capability: semantic_text_field_caps
313-
314-
from semantic_text
315-
| where knn(semantic_text_dense_field, [0, 1, 2], 10)
316-
| keep semantic_text_dense_field
317-
| sort semantic_text_dense_field asc
318-
;
319-
320-
semantic_text_dense_field:text
321-
all we have to decide is what to do with the time that is given to us
322-
be excellent to each other
323-
live long and prosper
324-
;

0 commit comments

Comments
 (0)