diff --git a/elasticsearch_dsl/query.py b/elasticsearch_dsl/query.py index 67508a42..652b3d57 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)) + # here we convert any iterables that are not strings to lists + if hasattr(value, "__iter__") and not isinstance(value, (str, list)): + value = list(value) + super()._setattr(name, value) class TermsSet(Query): diff --git a/tests/test_query.py b/tests/test_query.py index 3f7c61ec..64d8ba2f 100644 --- a/tests/test_query.py +++ b/tests/test_query.py @@ -81,8 +81,8 @@ def test_terms_to_dict() -> None: assert {"terms": {"_type": ["article", "section"]}} == query.Terms( _type=["article", "section"] ).to_dict() - assert {"terms": {"_type": ["article", "section"]}} == query.Terms( - _type=("article", "section") + assert {"terms": {"_type": ["article", "section"], "boost": 1.1}} == query.Terms( + _type=("article", "section"), boost=1.1 ).to_dict()