Skip to content

Commit 1b80f0e

Browse files
knn as a query option
Fixes #1770
1 parent b5800d4 commit 1b80f0e

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

elasticsearch_dsl/query.py

+4
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,10 @@ class Intervals(Query):
416416
name = "intervals"
417417

418418

419+
class Knn(Query):
420+
name = "knn"
421+
422+
419423
class Limit(Query):
420424
name = "limit"
421425

tests/test_query.py

+11
Original file line numberDiff line numberDiff line change
@@ -612,3 +612,14 @@ def test_expand_double_underscore_to_dot_setting():
612612
q = query.Term(comment__count=2)
613613
assert q.to_dict() == {"term": {"comment__count": 2}}
614614
utils.EXPAND__TO_DOT = True
615+
616+
617+
def test_knn_query():
618+
q = query.Knn(field="image-vector", query_vector=[-5, 9, -12], num_candidates=10)
619+
assert q.to_dict() == {
620+
"knn": {
621+
"field": "image-vector",
622+
"query_vector": [-5, 9, -12],
623+
"num_candidates": 10,
624+
}
625+
}

0 commit comments

Comments
 (0)