Skip to content

Commit 9e88c99

Browse files
committed
Fixes compatibility with Elasticsearch 8.18.1
Updates dependencies and code to ensure compatibility with Elasticsearch version 8.18.1. This involves: - Replacing `elasticsearch-dsl` with `elasticsearch` in requirements and code. - Updating the GitHub Actions CI configuration to test against newer versions of Python and Django. - Adjusting settings and test configurations. This resolves issues arising from API changes in the newer Elasticsearch client. Check the note on top of the elasticsearch dsl (https://elasticsearch-dsl.readthedocs.io/en/latest/)
1 parent e453aff commit 9e88c99

File tree

24 files changed

+78
-80
lines changed

24 files changed

+78
-80
lines changed

.github/workflows/ci.yml

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,21 @@ jobs:
1313
fail-fast: false
1414

1515
matrix:
16-
python-version: ["3.8", "3.9", "3.10", "3.11"]
17-
django-version: ["3.2", "4.1", "4.2"]
18-
es-dsl-version: ["6.4", "7.4"]
19-
es-version: ["8.10.2"]
16+
python-version: [ "3.8", "3.9", "3.10", "3.11", "3.12", "3.13" ]
17+
django-version: [ "3.2", "4.1", "4.2", "5.0", "5.1", "5.2" ]
18+
es-py-version: [ "6.4", "7.4", "8.18.1"]
2019

2120
exclude:
2221
- python-version: "3.11"
2322
django-version: "3.2"
23+
- python-version: "3.12"
24+
django-version: "3.2"
25+
- python-version: "3.13"
26+
django-version: "3.2"
27+
- es-py-version: "6.4"
28+
es-version: "8.10.2"
29+
- es-py-version: "7.4"
30+
es-version: "8.10.2"
2431

2532
steps:
2633
- name: Install and Run Elasticsearch
@@ -47,12 +54,12 @@ jobs:
4754
run: |
4855
python -m pip install --upgrade pip
4956
python -m pip install "Django==${{ matrix.django-version }}"
50-
python -m pip install "elasticsearch-dsl==${{ matrix.es-dsl-version }}"
57+
python -m pip install "elasticsearch==${{ matrix.es-py-version }}"
5158
python -m pip install -r requirements_test.txt
5259
53-
- name: Run tests with Python ${{ matrix.python-version }} and Django ${{ matrix.django-version }} and elasticsearch-dsl-py ${{ matrix.es-dsl-version }}
60+
- name: Run tests with Python ${{ matrix.python-version }} and Django ${{ matrix.django-version }} and elasticsearch-dsl-py ${{ matrix.es-py-version }}
5461
run: |
55-
TOX_ENV=$(echo "py${{ matrix.python-version }}-django-${{ matrix.django-version }}-es${{ matrix.es-dsl-version }}" | tr -d .)
62+
TOX_ENV=$(echo "py${{ matrix.python-version }}-django-${{ matrix.django-version }}-es${{ matrix.es-py-version }}" | tr -d .)
5663
python -m tox -e $TOX_ENV -- --elasticsearch
5764
python -m tox -e $TOX_ENV -- --elasticsearch --signal-processor celery
5865

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ The library is compatible with all Elasticsearch versions since 5.x
4646
.. code-block:: python
4747
4848
# Elasticsearch 8.x
49-
elasticsearch-dsl>=8.0.0,<9.0.0
49+
elasticsearch-dsl>=8.18.1,<9.0.0
5050
5151
# Elasticsearch 7.x
5252
elasticsearch-dsl>=7.0.0,<8.0.0

django_elasticsearch_dsl/apps.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from django.conf import settings
33
from django.utils.module_loading import import_string
44

5-
from elasticsearch_dsl.connections import connections
5+
from elasticsearch.dsl.connections import connections
66

77

88
class DEDConfig(AppConfig):

django_elasticsearch_dsl/documents.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from django import VERSION as DJANGO_VERSION
88
from django.db import models
99
from elasticsearch.helpers import bulk, parallel_bulk
10-
from elasticsearch_dsl import Document as DSLDocument
10+
from elasticsearch.dsl import Document as DSLDocument
1111
from six import iteritems
1212

1313
from .exceptions import ModelFieldNotMappedError

django_elasticsearch_dsl/fields.py

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
else:
1111
from django.utils.encoding import force_str
1212
from django.utils.functional import Promise
13-
from elasticsearch_dsl.field import (
13+
from elasticsearch.dsl.field import (
1414
Boolean,
1515
Byte,
1616
Completion,
@@ -100,36 +100,24 @@ class ObjectField(DEDField, Object):
100100
def _get_inner_field_data(self, obj, field_value_to_ignore=None):
101101
data = {}
102102

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

108-
if field._path == []:
109-
field._path = [name]
109+
if field._path == []:
110+
field._path = [name]
110111

112+
# This allows for retrieving data from an InnerDoc with prepare_field_name functions.
113+
prep_func = getattr(doc_instance, 'prepare_%s' % name, None)
114+
115+
if prep_func:
116+
data[name] = prep_func(obj)
117+
else:
111118
data[name] = field.get_value_from_instance(
112119
obj, field_value_to_ignore
113120
)
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-
)
133121

134122
# This allows for ObjectFields to be indexed from dicts with
135123
# 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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import unicode_literals, absolute_import
22
from datetime import datetime
33

4-
from elasticsearch_dsl import connections
4+
from elasticsearch.dsl import connections
55
from django.conf import settings
66
from django.core.management.base import BaseCommand, CommandError
77
from six.moves import input

django_elasticsearch_dsl/registries.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from django.core.exceptions import ObjectDoesNotExist
77
from django.core.exceptions import ImproperlyConfigured
8-
from elasticsearch_dsl import AttrDict
8+
from elasticsearch.dsl import AttrDict
99
from six import itervalues, iterkeys, iteritems
1010

1111
from django_elasticsearch_dsl.exceptions import RedeclaredFieldError

django_elasticsearch_dsl/search.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from django.db.models import Case, When
22
from django.db.models.fields import IntegerField
33

4-
from elasticsearch_dsl import Search as DSLSearch
4+
from elasticsearch.dsl import Search as DSLSearch
55

66

77
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

0 commit comments

Comments
 (0)