Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept Terms value to be any iterable #1887

Merged
merged 1 commit into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading