Skip to content

Commit

Permalink
Accept Terms value to be any iterable (#1887) (#1889)
Browse files Browse the repository at this point in the history
Co-authored-by: Roxane <r.bellot@octopusmind.info>
(cherry picked from commit 8cc2ed2)

Co-authored-by: roxanebellot <roxane.bellot@gmail.com>
  • Loading branch information
github-actions[bot] and roxanebellot authored Aug 22, 2024
1 parent 30c4474 commit 5bc9a62
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions elasticsearch_dsl/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 9 additions & 0 deletions tests/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=[])

Expand Down

0 comments on commit 5bc9a62

Please sign in to comment.