Skip to content

Commit

Permalink
Add ScriptScore query
Browse files Browse the repository at this point in the history
  • Loading branch information
sethmlarson committed Dec 3, 2020
1 parent 3e5703f commit 16304df
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions elasticsearch_dsl/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,11 @@ class Script(Query):
name = "script"


class ScriptScore(Query):
name = "script_score"
_param_defs = {"query": {"type": "query"}}


class Type(Query):
name = "type"

Expand Down
15 changes: 15 additions & 0 deletions tests/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,3 +538,18 @@ def test_function_score_from_dict():
assert isinstance(sf, function.BoostFactor)
assert 6 == sf.value
assert {"boost_factor": 6} == sf.to_dict()


def test_script_score():
d = {
"script_score": {
"query": {"match_all": {}},
"script": {"source": "...", "params": {}},
}
}
q = query.Q(d)

assert isinstance(q, query.ScriptScore)
assert isinstance(q.query, query.MatchAll)
assert q.script == {"source": "...", "params": {}}
assert q.to_dict() == d

0 comments on commit 16304df

Please sign in to comment.