Skip to content

Commit 00b6cbf

Browse files
authored
Merge pull request #1 from srfonso/fix/aggs-proxy-import-error
Fix AggsProxy import with elasticsearch-dsl team approach barseghyanartur#319
2 parents d83900f + 276280e commit 00b6cbf

File tree

2 files changed

+38
-26
lines changed

2 files changed

+38
-26
lines changed

src/django_elasticsearch_dsl_drf/filter_backends/suggester/functional.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,15 @@
6767
>>>
6868
>>> model = Publisher # The model associate with this Document
6969
"""
70-
from elasticsearch_dsl.search import AggsProxy
70+
try: # code for 8.13 (requires 8.13.1)
71+
# This should not be imported in external projects, as it is a internal tool.
72+
# See https://github.com/barseghyanartur/django-elasticsearch-dsl-drf/pull/316/files#r1596499499
73+
from elasticsearch_dsl.search_base import AggsProxy
74+
except ImportError:
75+
# backward-compatible (older than 8.13)
76+
from elasticsearch_dsl.search import AggsProxy
77+
78+
from elasticsearch_dsl.search_base import AggsProxy
7179

7280
from django_elasticsearch_dsl_drf.constants import (
7381
FUNCTIONAL_SUGGESTER_TERM_MATCH,

src/django_elasticsearch_dsl_drf/utils.py

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"""
44

55
import datetime
6-
from elasticsearch_dsl.search import AggsProxy
76

87

98
__title__ = 'django_elasticsearch_dsl_drf.utils'
@@ -15,40 +14,45 @@
1514
'EmptySearch',
1615
)
1716

17+
try:
18+
# code for 8.13 (requires 8.13.1)
19+
from elasticsearch_dsl import EmptySearch
20+
except ImportError:
21+
from elasticsearch_dsl.search import AggsProxy
1822

19-
class EmptySearch(object):
20-
"""Empty Search."""
23+
class EmptySearch(object):
24+
"""Empty Search."""
2125

22-
def __init__(self, *args, **kwargs):
23-
self.aggs = AggsProxy('')
24-
self._highlight = {}
25-
self._sort = []
26-
self.total = 0
26+
def __init__(self, *args, **kwargs):
27+
self.aggs = AggsProxy('')
28+
self._highlight = {}
29+
self._sort = []
30+
self.total = 0
2731

28-
def __len__(self):
29-
return 0
32+
def __len__(self):
33+
return 0
3034

31-
def __iter__(self):
32-
return iter([])
35+
def __iter__(self):
36+
return iter([])
3337

34-
def __getitem__(self, *args, **kwargs):
35-
return self
38+
def __getitem__(self, *args, **kwargs):
39+
return self
3640

37-
def highlight(self, *args, **kwargs):
38-
return self
41+
def highlight(self, *args, **kwargs):
42+
return self
3943

40-
def sort(self, *args, **kwargs):
41-
return self
44+
def sort(self, *args, **kwargs):
45+
return self
4246

43-
@property
44-
def hits(self):
45-
return self
47+
@property
48+
def hits(self):
49+
return self
4650

47-
def execute(self, *args, **kwargs):
48-
return self
51+
def execute(self, *args, **kwargs):
52+
return self
4953

50-
def to_dict(self, *args, **kwargs):
51-
return {}
54+
def to_dict(self, *args, **kwargs):
55+
return {}
5256

5357

5458
class DictionaryProxy(object):

0 commit comments

Comments
 (0)