@@ -27,6 +27,9 @@ PUT my-image-index
27
27
},
28
28
"file-type": {
29
29
"type": "keyword"
30
+ },
31
+ "title": {
32
+ "type": "text"
30
33
}
31
34
}
32
35
}
@@ -39,11 +42,11 @@ PUT my-image-index
39
42
----
40
43
POST my-image-index/_bulk?refresh=true
41
44
{ "index": { "_id": "1" } }
42
- { "image-vector": [1, 5, -20], "file-type": "jpg" }
45
+ { "image-vector": [1, 5, -20], "file-type": "jpg", "title": "mountain lake" }
43
46
{ "index": { "_id": "2" } }
44
- { "image-vector": [42, 8, -15], "file-type": "png" }
47
+ { "image-vector": [42, 8, -15], "file-type": "png", "title": "frozen lake" }
45
48
{ "index": { "_id": "3" } }
46
- { "image-vector": [15, 11, 23], "file-type": "jpg" }
49
+ { "image-vector": [15, 11, 23], "file-type": "jpg", "title": "mountain lake lodge" }
47
50
----
48
51
//TEST[continued]
49
52
@@ -176,6 +179,47 @@ POST my-image-index/_search
176
179
----
177
180
//TEST[continued]
178
181
182
+ [[knn-query-in-hybrid-search]]
183
+ ==== Hybrid search with knn query
184
+ Knn query can be used as a part of hybrid search, where knn query is combined
185
+ with other lexical queries. For example, the query below finds documents with
186
+ `title` matching `mountain lake`, and combines them with the top 10 documents
187
+ that have the closest image vectors to the `query_vector`. The combined documents
188
+ are then scored and the top 3 top scored documents are returned.
189
+
190
+ +
191
+ [source,console]
192
+ ----
193
+ POST my-image-index/_search
194
+ {
195
+ "size" : 3,
196
+ "query": {
197
+ "bool": {
198
+ "should": [
199
+ {
200
+ "match": {
201
+ "title": {
202
+ "query": "mountain lake",
203
+ "boost": 1
204
+ }
205
+ }
206
+ },
207
+ {
208
+ "knn": {
209
+ "field": "image-vector",
210
+ "query_vector": [-5, 9, -12],
211
+ "num_candidates": 10,
212
+ "boost": 2
213
+ }
214
+ }
215
+ ]
216
+ }
217
+ }
218
+ }
219
+ ----
220
+ //TEST[continued]
221
+
222
+
179
223
[[knn-query-with-nested-query]]
180
224
==== Knn query inside a nested query
181
225
@@ -219,4 +263,3 @@ Thus, the final results from aggregations contain
219
263
`num_candidates * number_of_shards` documents. This is different from
220
264
the <<knn-search,top level knn section>> where aggregations are
221
265
calculated on the global top k nearest documents.
222
-
0 commit comments