diff --git a/src/django_elasticsearch_dsl_drf/filter_backends/suggester/functional.py b/src/django_elasticsearch_dsl_drf/filter_backends/suggester/functional.py index 909f0d26..97503866 100644 --- a/src/django_elasticsearch_dsl_drf/filter_backends/suggester/functional.py +++ b/src/django_elasticsearch_dsl_drf/filter_backends/suggester/functional.py @@ -67,7 +67,15 @@ >>> >>> model = Publisher # The model associate with this Document """ -from elasticsearch_dsl.search import AggsProxy +try: # code for 8.13 (requires 8.13.1) + # This should not be imported in external projects, as it is a internal tool. + # See https://github.com/barseghyanartur/django-elasticsearch-dsl-drf/pull/316/files#r1596499499 + from elasticsearch_dsl.search_base import AggsProxy +except ImportError: + # backward-compatible (older than 8.13) + from elasticsearch_dsl.search import AggsProxy + +from elasticsearch_dsl.search_base import AggsProxy from django_elasticsearch_dsl_drf.constants import ( FUNCTIONAL_SUGGESTER_TERM_MATCH, diff --git a/src/django_elasticsearch_dsl_drf/utils.py b/src/django_elasticsearch_dsl_drf/utils.py index 3487565a..f4e9b7c9 100644 --- a/src/django_elasticsearch_dsl_drf/utils.py +++ b/src/django_elasticsearch_dsl_drf/utils.py @@ -3,7 +3,6 @@ """ import datetime -from elasticsearch_dsl.search import AggsProxy __title__ = 'django_elasticsearch_dsl_drf.utils' @@ -15,40 +14,45 @@ 'EmptySearch', ) +try: + # code for 8.13 (requires 8.13.1) + from elasticsearch_dsl import EmptySearch +except ImportError: + from elasticsearch_dsl.search import AggsProxy -class EmptySearch(object): - """Empty Search.""" + class EmptySearch(object): + """Empty Search.""" - def __init__(self, *args, **kwargs): - self.aggs = AggsProxy('') - self._highlight = {} - self._sort = [] - self.total = 0 + def __init__(self, *args, **kwargs): + self.aggs = AggsProxy('') + self._highlight = {} + self._sort = [] + self.total = 0 - def __len__(self): - return 0 + def __len__(self): + return 0 - def __iter__(self): - return iter([]) + def __iter__(self): + return iter([]) - def __getitem__(self, *args, **kwargs): - return self + def __getitem__(self, *args, **kwargs): + return self - def highlight(self, *args, **kwargs): - return self + def highlight(self, *args, **kwargs): + return self - def sort(self, *args, **kwargs): - return self + def sort(self, *args, **kwargs): + return self - @property - def hits(self): - return self + @property + def hits(self): + return self - def execute(self, *args, **kwargs): - return self + def execute(self, *args, **kwargs): + return self - def to_dict(self, *args, **kwargs): - return {} + def to_dict(self, *args, **kwargs): + return {} class DictionaryProxy(object):