33# top-n query at the shard level 
44
55knnSearch
6- required_capability: knn_function 
6+ required_capability: knn_function_v2 
77
88// tag::knn-function[]
99from colors metadata _score 
10- | where knn(rgb_vector, [0, 120, 0]) 
10+ | where knn(rgb_vector, [0, 120, 0], 10 ) 
1111| sort _score desc, color asc
1212// end::knn-function[]
1313| keep color, rgb_vector
@@ -29,31 +29,12 @@ chartreuse | [127.0, 255.0, 0.0]
2929// end::knn-function-result[]
3030;
3131
32- knnSearchWithKOption
33- required_capability: knn_function
34- 
35- // tag::knn-function-options[]
36- from colors metadata _score 
37- | where knn(rgb_vector, [0,255,255], {"k": 4})
38- | sort _score desc, color asc
39- // end::knn-function-options[]
40- | keep color, rgb_vector
41- | limit 4
42- ;
43- 
44- color:text  | rgb_vector:dense_vector
45- cyan        | [0.0, 255.0, 255.0]
46- turquoise   | [64.0, 224.0, 208.0]
47- aqua marine | [127.0, 255.0, 212.0]
48- teal        | [0.0, 128.0, 128.0]
49- ;
50- 
51- # https://github.com/elastic/elasticsearch/issues/129550
32+ # https://github.com/elastic/elasticsearch/issues/129550 - Add as an example to knn function documentation
5233knnSearchWithSimilarityOption-Ignore
53- required_capability: knn_function 
34+ required_capability: knn_function_v2 
5435
5536from colors metadata _score 
56- | where knn(rgb_vector, [255,192,203], {"k":  140, "similarity": 40})
37+ | where knn(rgb_vector, [255,192,203], 140, { "similarity": 40})
5738| sort _score desc, color asc
5839| keep color, rgb_vector
5940;
@@ -63,14 +44,13 @@ pink       | [255.0, 192.0, 203.0]
6344peach puff | [255.0, 218.0, 185.0]
6445bisque     | [255.0, 228.0, 196.0]
6546wheat      | [245.0, 222.0, 179.0]
66- 
6747;
6848
6949knnHybridSearch
70- required_capability: knn_function 
50+ required_capability: knn_function_v2 
7151
7252from colors metadata _score 
73- | where match(color, "blue") or knn(rgb_vector, [65,105,225], {"k":  140} )
53+ | where match(color, "blue") or knn(rgb_vector, [65,105,225], 140)
7454| where primary == true
7555| sort _score desc, color asc
7656| keep color, rgb_vector
@@ -90,10 +70,10 @@ yellow     | [255.0, 255.0, 0.0]
9070;
9171
9272knnWithMultipleFunctions
93- required_capability: knn_function 
73+ required_capability: knn_function_v2 
9474
9575from colors metadata _score
96- | where knn(rgb_vector, [128,128,0], {"k":  140} ) and match(color, "olive") 
76+ | where knn(rgb_vector, [128,128,0], 140) and match(color, "olive") 
9777| sort _score desc, color asc
9878| keep color, rgb_vector
9979;
@@ -103,11 +83,11 @@ olive            | [128.0, 128.0, 0.0]
10383;
10484
10585knnAfterKeep
106- required_capability: knn_function 
86+ required_capability: knn_function_v2 
10787
10888from colors metadata _score
10989| keep rgb_vector, color, _score 
110- | where knn(rgb_vector, [128,255,0], {"k":  140} )
90+ | where knn(rgb_vector, [128,255,0], 140)
11191| sort _score desc, color asc
11292| keep rgb_vector
11393| limit 5
@@ -122,11 +102,11 @@ rgb_vector:dense_vector
122102;
123103
124104knnAfterDrop
125- required_capability: knn_function 
105+ required_capability: knn_function_v2 
126106
127107from colors metadata _score
128108| drop primary
129- | where knn(rgb_vector, [128,250,0], {"k":  140} )
109+ | where knn(rgb_vector, [128,250,0], 140)
130110| sort _score desc, color asc
131111| keep color, rgb_vector
132112| limit 5
@@ -141,11 +121,11 @@ lime           | [0.0, 255.0, 0.0]
141121;
142122
143123knnAfterEval
144- required_capability: knn_function 
124+ required_capability: knn_function_v2 
145125
146126from colors metadata _score
147127| eval composed_name = locate(color, " ") > 0 
148- | where knn(rgb_vector, [128,128,0], {"k":  140} )
128+ | where knn(rgb_vector, [128,128,0], 140)
149129| sort _score desc, color asc
150130| keep color, composed_name 
151131| limit 5
@@ -160,11 +140,11 @@ golden rod | true
160140;
161141
162142knnWithConjunction
163- required_capability: knn_function 
143+ required_capability: knn_function_v2 
164144
165145# TODO We need kNN prefiltering here so we get more candidates that pass the filter
166146from colors metadata _score 
167- | where knn(rgb_vector, [255,255,238], {"k":  140} ) and hex_code like "#FFF*" 
147+ | where knn(rgb_vector, [255,255,238], 140) and hex_code like "#FFF*" 
168148| sort _score desc, color asc
169149| keep color, hex_code, rgb_vector
170150| limit 10
@@ -181,11 +161,11 @@ yellow        | #FFFF00          | [255.0, 255.0, 0.0]
181161;
182162
183163knnWithDisjunctionAndFiltersConjunction
184- required_capability: knn_function 
164+ required_capability: knn_function_v2 
185165
186166# TODO We need kNN prefiltering here so we get more candidates that pass the filter
187167from colors metadata _score 
188- | where (knn(rgb_vector, [0,255,255], {"k":  140} ) or knn(rgb_vector, [128, 0, 255], {"k":  140} )) and primary == true 
168+ | where (knn(rgb_vector, [0,255,255], 140) or knn(rgb_vector, [128, 0, 255], 140)) and primary == true 
189169| keep color, rgb_vector, _score
190170| sort _score desc, color asc
191171| drop _score
@@ -205,11 +185,11 @@ yellow     | [255.0, 255.0, 0.0]
205185;
206186
207187knnWithNonPushableConjunction
208- required_capability: knn_function 
188+ required_capability: knn_function_v2 
209189
210190from colors metadata _score
211191| eval composed_name = locate(color, " ") > 0 
212- | where knn(rgb_vector, [128,128,0], {"k":  140} ) and composed_name == false
192+ | where knn(rgb_vector, [128,128,0], 140) and composed_name == false
213193| sort _score desc, color asc
214194| keep color, composed_name
215195| limit 10
@@ -230,10 +210,10 @@ maroon     | false
230210
231211# https://github.com/elastic/elasticsearch/issues/129550
232212testKnnWithNonPushableDisjunctions-Ignore
233- required_capability: knn_function 
213+ required_capability: knn_function_v2 
234214
235215from colors metadata _score 
236- | where knn(rgb_vector, [128,128,0], {"k":  140, "similarity": 30}) or length(color) > 10 
216+ | where knn(rgb_vector, [128,128,0], 140, { "similarity": 30}) or length(color) > 10 
237217| sort _score desc, color asc
238218| keep color 
239219;
@@ -247,10 +227,10 @@ papaya whip
247227
248228# https://github.com/elastic/elasticsearch/issues/129550
249229testKnnWithNonPushableDisjunctionsOnComplexExpressions-Ignore
250- required_capability: knn_function 
230+ required_capability: knn_function_v2 
251231
252232from colors metadata _score 
253- | where (knn(rgb_vector, [128,128,0], {"k":  140, "similarity": 70}) and length(color) < 10) or (knn(rgb_vector, [128,0,128], {"k":  140, "similarity": 60}) and primary == false) 
233+ | where (knn(rgb_vector, [128,128,0], 140, { "similarity": 70}) and length(color) < 10) or (knn(rgb_vector, [128,0,128], 140, { "similarity": 60}) and primary == false) 
254234| sort _score desc, color asc
255235| keep color, primary
256236;
@@ -262,24 +242,24 @@ indigo       | false
262242;
263243
264244testKnnInStatsNonPushable
265- required_capability: knn_function 
245+ required_capability: knn_function_v2 
266246
267247from colors 
268248| where length(color) < 10 
269- | stats c = count(*) where knn(rgb_vector, [128,128,255], {"k":  140} )
249+ | stats c = count(*) where knn(rgb_vector, [128,128,255], 140)
270250;
271251
272252c: long 
27325350      
274254;
275255
276256testKnnInStatsWithGrouping
277- required_capability: knn_function 
257+ required_capability: knn_function_v2 
278258required_capability: full_text_functions_in_stats_where
279259
280260from colors 
281261| where length(color) < 10 
282- | stats c = count(*) where knn(rgb_vector, [128,128,255], {"k":  140} ) by primary
262+ | stats c = count(*) where knn(rgb_vector, [128,128,255], 140) by primary
283263;
284264
285265c: long       | primary: boolean    
0 commit comments