Skip to content

Commit 8cc2ed2

Browse files
roxanebellotRoxane
and
Roxane
authored
Accept Terms value to be any iterable (#1887)
Co-authored-by: Roxane <[email protected]>
1 parent b762aae commit 8cc2ed2

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

elasticsearch_dsl/query.py

+3
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,9 @@ class Term(Query):
550550
class Terms(Query):
551551
name = "terms"
552552

553+
def _setattr(self, name: str, value: Any) -> None:
554+
super()._setattr(name, list(value))
555+
553556

554557
class TermsSet(Query):
555558
name = "terms_set"

tests/test_query.py

+9
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,15 @@ def test_term_to_dict() -> None:
7777
assert {"term": {"_type": "article"}} == query.Term(_type="article").to_dict()
7878

7979

80+
def test_terms_to_dict() -> None:
81+
assert {"terms": {"_type": ["article", "section"]}} == query.Terms(
82+
_type=["article", "section"]
83+
).to_dict()
84+
assert {"terms": {"_type": ["article", "section"]}} == query.Terms(
85+
_type=("article", "section")
86+
).to_dict()
87+
88+
8089
def test_bool_to_dict() -> None:
8190
bool = query.Bool(must=[query.Match(f="value")], should=[])
8291

0 commit comments

Comments
 (0)