Skip to content

Commit 3553928

Browse files
committed
Switch from elasticsearch-dsl-py dependency to elasticsearch-py
This commit switches the dependency of this library from elasticsearch-dsl-py to elasticsearch-py since the former was merged into the latter.
1 parent 0303f19 commit 3553928

File tree

19 files changed

+73
-81
lines changed

19 files changed

+73
-81
lines changed

README.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ Django Elasticsearch DSL
1212
:target: https://django-elasticsearch-dsl.readthedocs.io/en/latest/
1313

1414
Django Elasticsearch DSL is a package that allows indexing of django models in elasticsearch.
15-
It is built as a thin wrapper around elasticsearch-dsl-py_
16-
so you can use all the features developed by the elasticsearch-dsl-py team.
15+
It is built as a thin wrapper around elasticsearch-py_
16+
so you can use all the features developed by the elasticsearch-py team.
1717

1818
You can view the full documentation at https://django-elasticsearch-dsl.readthedocs.io
1919

20-
.. _elasticsearch-dsl-py: https://github.com/elastic/elasticsearch-dsl-py
20+
.. _elasticsearch-py: https://github.com/elastic/elasticsearch-py
2121

2222
Features
2323
--------
2424

25-
- Based on elasticsearch-dsl-py_ so you can make queries with the Search_ class.
25+
- Based on elasticsearch-py_ so you can make queries with the Search_ class.
2626
- Django signal receivers on save and delete for keeping Elasticsearch in sync.
2727
- Management commands for creating, deleting, rebuilding and populating indices.
2828
- Elasticsearch auto mapping from django models fields.

django_elasticsearch_dsl/apps.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
from django.apps import AppConfig
22
from django.conf import settings
33
from django.utils.module_loading import import_string
4-
5-
from elasticsearch_dsl.connections import connections
4+
from elasticsearch.dsl.connections import connections
65

76

87
class DEDConfig(AppConfig):

django_elasticsearch_dsl/documents.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
from django import VERSION as DJANGO_VERSION
88
from django.db import models
9+
from elasticsearch.dsl import Document as DSLDocument
910
from elasticsearch.helpers import bulk, parallel_bulk
10-
from elasticsearch_dsl import Document as DSLDocument
1111
from six import iteritems
1212

1313
from .exceptions import ModelFieldNotMappedError
@@ -21,7 +21,8 @@
2121
KeywordField,
2222
LongField,
2323
ShortField,
24-
TextField, TimeField,
24+
TextField,
25+
TimeField,
2526
)
2627
from .search import Search
2728
from .signals import post_index
@@ -219,14 +220,13 @@ def _get_actions(self, object_list, action):
219220
for object_instance in object_list:
220221
if action == 'delete' or self.should_index_object(object_instance):
221222
yield self._prepare_action(object_instance, action)
222-
223+
223224
def get_actions(self, object_list, action):
224225
"""
225226
Generate the elasticsearch payload.
226227
"""
227228
return self._get_actions(object_list, action)
228229

229-
230230
def _bulk(self, *args, **kwargs):
231231
"""Helper for switching between normal and parallel bulk operation"""
232232
parallel = kwargs.pop('parallel', False)

django_elasticsearch_dsl/fields.py

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
from django.utils.encoding import force_text as force_str
1010
else:
1111
from django.utils.encoding import force_str
12+
1213
from django.utils.functional import Promise
13-
from elasticsearch_dsl.field import (
14+
from elasticsearch.dsl.field import (
1415
Boolean,
1516
Byte,
1617
Completion,
@@ -22,14 +23,14 @@
2223
GeoShape,
2324
Integer,
2425
Ip,
26+
Keyword,
2527
Long,
2628
Nested,
2729
Object,
2830
ScaledFloat,
31+
SearchAsYouType,
2932
Short,
30-
Keyword,
3133
Text,
32-
SearchAsYouType,
3334
)
3435

3536
from .exceptions import VariableLookupError
@@ -100,36 +101,24 @@ class ObjectField(DEDField, Object):
100101
def _get_inner_field_data(self, obj, field_value_to_ignore=None):
101102
data = {}
102103

103-
if hasattr(self, 'properties'):
104-
for name, field in self.properties.to_dict().items():
105-
if not isinstance(field, DEDField):
106-
continue
104+
doc_instance = self._doc_class()
105+
for name, field in self._doc_class._doc_type.mapping.properties._params.get(
106+
'properties', {}).items(): # noqa
107+
if not isinstance(field, DEDField):
108+
continue
109+
110+
if field._path == []:
111+
field._path = [name]
107112

108-
if field._path == []:
109-
field._path = [name]
113+
# This allows for retrieving data from an InnerDoc with prepare_field_name functions.
114+
prep_func = getattr(doc_instance, 'prepare_%s' % name, None)
110115

116+
if prep_func:
117+
data[name] = prep_func(obj)
118+
else:
111119
data[name] = field.get_value_from_instance(
112120
obj, field_value_to_ignore
113121
)
114-
else:
115-
doc_instance = self._doc_class()
116-
for name, field in self._doc_class._doc_type.mapping.properties._params.get(
117-
'properties', {}).items(): # noqa
118-
if not isinstance(field, DEDField):
119-
continue
120-
121-
if field._path == []:
122-
field._path = [name]
123-
124-
# This allows for retrieving data from an InnerDoc with prepare_field_name functions.
125-
prep_func = getattr(doc_instance, 'prepare_%s' % name, None)
126-
127-
if prep_func:
128-
data[name] = prep_func(obj)
129-
else:
130-
data[name] = field.get_value_from_instance(
131-
obj, field_value_to_ignore
132-
)
133122

134123
# This allows for ObjectFields to be indexed from dicts with
135124
# dynamic keys (i.e. keys/fields not defined in 'properties')

django_elasticsearch_dsl/indices.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from copy import deepcopy
22

3-
from elasticsearch_dsl import Index as DSLIndex
3+
from elasticsearch.dsl import Index as DSLIndex
44
from six import python_2_unicode_compatible
55

66
from .apps import DEDConfig

django_elasticsearch_dsl/management/commands/search_index.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
from __future__ import unicode_literals, absolute_import
1+
from __future__ import absolute_import, unicode_literals
2+
23
from datetime import datetime
34

4-
from elasticsearch_dsl import connections
55
from django.conf import settings
66
from django.core.management.base import BaseCommand, CommandError
7+
from elasticsearch.dsl import connections
78
from six.moves import input
9+
810
from ...registries import registry
911

1012

django_elasticsearch_dsl/registries.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
from collections import defaultdict
22
from copy import deepcopy
3-
43
from itertools import chain
54

6-
from django.core.exceptions import ObjectDoesNotExist
7-
from django.core.exceptions import ImproperlyConfigured
8-
from elasticsearch_dsl import AttrDict
9-
from six import itervalues, iterkeys, iteritems
5+
from django.core.exceptions import ImproperlyConfigured, ObjectDoesNotExist
6+
from elasticsearch.dsl import AttrDict
7+
from six import iteritems, iterkeys, itervalues
108

119
from django_elasticsearch_dsl.exceptions import RedeclaredFieldError
10+
1211
from .apps import DEDConfig
1312

1413

django_elasticsearch_dsl/search.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from django.db.models import Case, When
22
from django.db.models.fields import IntegerField
3-
4-
from elasticsearch_dsl import Search as DSLSearch
3+
from elasticsearch.dsl import Search as DSLSearch
54

65

76
class Search(DSLSearch):

django_elasticsearch_dsl/test/testcases.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import re
22

33
from django.test.utils import captured_stderr
4-
from elasticsearch_dsl.connections import connections
4+
from elasticsearch.dsl.connections import connections
55

66
from ..registries import registry
77

docs/source/es_index.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Index
44
In typical scenario using `class Index` on a `Document` class is sufficient to perform any action.
55
In a few cases though it can be useful to manipulate an Index object directly.
66

7-
To define an Elasticsearch index you must instantiate a ``elasticsearch_dsl.Index`` class
7+
To define an Elasticsearch index you must instantiate a ``elasticsearch.dsl.Index`` class
88
and set the name and settings of the index.
99
After you instantiate your class,
1010
you need to associate it with the Document you want to put in this Elasticsearch index
@@ -14,7 +14,7 @@ and also add the `registry.register_document` decorator.
1414
.. code-block:: python
1515
1616
# documents.py
17-
from elasticsearch_dsl import Index
17+
from elasticsearch.dsl import Index
1818
from django_elasticsearch_dsl import Document
1919
from .models import Car, Manufacturer
2020

0 commit comments

Comments
 (0)