Skip to content

Commit e49d851

Browse files
Fixed use of dictionaries as values in Terms query (#1921) (#1922)
Fixes #1920
1 parent 3f072c3 commit e49d851

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

elasticsearch_dsl/query.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ class Terms(Query):
552552

553553
def _setattr(self, name: str, value: Any) -> None:
554554
# here we convert any iterables that are not strings to lists
555-
if hasattr(value, "__iter__") and not isinstance(value, (str, list)):
555+
if hasattr(value, "__iter__") and not isinstance(value, (str, list, dict)):
556556
value = list(value)
557557
super()._setattr(name, value)
558558

tests/test_query.py

+8
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,14 @@ def test_terms_to_dict() -> None:
8484
assert {"terms": {"_type": ["article", "section"], "boost": 1.1}} == query.Terms(
8585
_type=("article", "section"), boost=1.1
8686
).to_dict()
87+
assert {"terms": {"_type": "article", "boost": 1.1}} == query.Terms(
88+
_type="article", boost=1.1
89+
).to_dict()
90+
assert {
91+
"terms": {"_id": {"index": "my-other-index", "id": "my-id"}, "boost": 1.1}
92+
} == query.Terms(
93+
_id={"index": "my-other-index", "id": "my-id"}, boost=1.1
94+
).to_dict()
8795

8896

8997
def test_bool_to_dict() -> None:

0 commit comments

Comments
 (0)