From f434f462979af6cbe3956bab619a13a57acf3537 Mon Sep 17 00:00:00 2001 From: Roxane Date: Mon, 17 Jul 2023 16:40:21 +0200 Subject: [PATCH] Accept Terms value to be any iterable --- elasticsearch_dsl/query.py | 3 +++ tests/test_query.py | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/elasticsearch_dsl/query.py b/elasticsearch_dsl/query.py index 993213c6..67508a42 100644 --- a/elasticsearch_dsl/query.py +++ b/elasticsearch_dsl/query.py @@ -550,6 +550,9 @@ class Term(Query): class Terms(Query): name = "terms" + def _setattr(self, name: str, value: Any) -> None: + super()._setattr(name, list(value)) + class TermsSet(Query): name = "terms_set" diff --git a/tests/test_query.py b/tests/test_query.py index 601f5102..3f7c61ec 100644 --- a/tests/test_query.py +++ b/tests/test_query.py @@ -77,6 +77,15 @@ def test_term_to_dict() -> None: assert {"term": {"_type": "article"}} == query.Term(_type="article").to_dict() +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") + ).to_dict() + + def test_bool_to_dict() -> None: bool = query.Bool(must=[query.Match(f="value")], should=[])