From 82e4924eb4484221fc6fbf23f76627e45be6cee5 Mon Sep 17 00:00:00 2001 From: Jair Henrique Date: Mon, 9 Sep 2024 10:22:50 -0300 Subject: [PATCH] Accepts boost param on Terms --- elasticsearch_dsl/query.py | 5 ++++- tests/test_query.py | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/elasticsearch_dsl/query.py b/elasticsearch_dsl/query.py index 67508a42..866951fe 100644 --- a/elasticsearch_dsl/query.py +++ b/elasticsearch_dsl/query.py @@ -551,7 +551,10 @@ class Terms(Query): name = "terms" def _setattr(self, name: str, value: Any) -> None: - super()._setattr(name, list(value)) + if name != "boost": + value = list(value) + + super()._setattr(name, value) class TermsSet(Query): diff --git a/tests/test_query.py b/tests/test_query.py index 3f7c61ec..183e283b 100644 --- a/tests/test_query.py +++ b/tests/test_query.py @@ -86,6 +86,12 @@ def test_terms_to_dict() -> None: ).to_dict() +def test_terms_to_dict_should_accept_boost_param() -> None: + assert {"terms": {"_type": ["article", "section"], "boost": 2}} == query.Terms( + _type=["article", "section"], boost=2 + ).to_dict() + + def test_bool_to_dict() -> None: bool = query.Bool(must=[query.Match(f="value")], should=[])