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

Fix AggsProxy import with elasticsearch-dsl team approach #319

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
54 changes: 29 additions & 25 deletions src/django_elasticsearch_dsl_drf/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"""

import datetime
from elasticsearch_dsl.search import AggsProxy


__title__ = 'django_elasticsearch_dsl_drf.utils'
Expand All @@ -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):
Expand Down