Skip to content

Commit

Permalink
Fix importing collapse from dict (#1689)
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelgrinberg committed Dec 22, 2023
1 parent d66bd2f commit f0c5045
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 3 additions & 2 deletions elasticsearch_dsl/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ def __init__(self, using="default", index=None, doc_type=None, extra=None):

self._doc_type = []
self._doc_type_map = {}
self._collapse = {}
if isinstance(doc_type, (tuple, list)):
self._doc_type.extend(doc_type)
elif isinstance(doc_type, collections.abc.Mapping):
Expand Down Expand Up @@ -294,7 +293,6 @@ def _clone(self):
s = self.__class__(
using=self._using, index=self._index, doc_type=self._doc_type
)
s._collapse = self._collapse.copy()
s._doc_type_map = self._doc_type_map.copy()
s._extra = self._extra.copy()
s._params = self._params.copy()
Expand Down Expand Up @@ -408,6 +406,7 @@ def _clone(self):
s = super()._clone()

s._response_class = self._response_class
s._collapse = self._collapse.copy()
s._sort = self._sort[:]
s._source = copy.copy(self._source) if self._source is not None else None
s._highlight = self._highlight.copy()
Expand Down Expand Up @@ -446,6 +445,8 @@ def update_from_dict(self, d):
self.aggs._params = {
"aggs": {name: A(value) for (name, value) in aggs.items()}
}
if "collapse" in d:
self._collapse = d.pop("collapse")
if "sort" in d:
self._sort = d.pop("sort")
if "_source" in d:
Expand Down
2 changes: 2 additions & 0 deletions tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,10 +544,12 @@ def test_update_from_dict():
s = search.Search()
s.update_from_dict({"indices_boost": [{"important-documents": 2}]})
s.update_from_dict({"_source": ["id", "name"]})
s.update_from_dict({"collapse": {"field": "user_id"}})

assert {
"indices_boost": [{"important-documents": 2}],
"_source": ["id", "name"],
"collapse": {"field": "user_id"},
} == s.to_dict()


Expand Down

0 comments on commit f0c5045

Please sign in to comment.