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

Port to opensearch #1

Open
wants to merge 3 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
24 changes: 12 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ jobs:
fail-fast: false

matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
django-version: ["3.2", "4.1", "4.2"]
es-dsl-version: ["6.4", "7.4"]
es-version: ["8.10.2"]
python-version: ["3.9", "3.11"]
django-version: ["3.2", "4.2"]
open-dsl-version: ["2.2", "2.4"]

exclude:
- python-version: "3.11"
django-version: "3.2"

steps:
- name: Install and Run Elasticsearch
uses: elastic/elastic-github-actions/elasticsearch@master
- name: Install and Run Opensearch
uses: esmarkowski/opensearch-github-[email protected]
with:
stack-version: ${{ matrix.es-version }}
version: 2.12.0
security-disabled: true

- uses: actions/checkout@v4

Expand All @@ -47,14 +47,14 @@ jobs:
run: |
python -m pip install --upgrade pip
python -m pip install "Django==${{ matrix.django-version }}"
python -m pip install "elasticsearch-dsl==${{ matrix.es-dsl-version }}"
python -m pip install "opensearch-py==${{ matrix.open-dsl-version }}.0"
python -m pip install -r requirements_test.txt

- name: Run tests with Python ${{ matrix.python-version }} and Django ${{ matrix.django-version }} and elasticsearch-dsl-py ${{ matrix.es-dsl-version }}
- name: Run tests with Python ${{ matrix.python-version }} and Django ${{ matrix.django-version }} and opensearch-=py ${{ matrix.open-dsl-version }}
run: |
TOX_ENV=$(echo "py${{ matrix.python-version }}-django-${{ matrix.django-version }}-es${{ matrix.es-dsl-version }}" | tr -d .)
python -m tox -e $TOX_ENV -- --elasticsearch
python -m tox -e $TOX_ENV -- --elasticsearch --signal-processor celery
TOX_ENV=$(echo "py${{ matrix.python-version }}-django-${{ matrix.django-version }}-open${{ matrix.open-dsl-version }}" | tr -d .)
python -m tox -e $TOX_ENV -- --elasticsearch http://127.0.0.1:9200
python -m tox -e $TOX_ENV -- --elasticsearch http://127.0.0.1:9200 --signal-processor celery

- name: Publish Coverage Report
uses: codecov/codecov-action@v3
9 changes: 9 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
exclude: "(.idea|node_modules|.tox)"
repos:
- repo: https://github.com/adamchainz/django-upgrade
rev: "1.15.0"
hooks:
- id: django-upgrade
args: [--target-version, "3.2"]
16 changes: 8 additions & 8 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Types of Contributions
Report Bugs
~~~~~~~~~~~

Report bugs at https://github.com/sabricot/django-elasticsearch-dsl/issues.
Report bugs at https://github.com/sabricot/django-opensearch-dsl/issues.

If you are reporting a bug, please include:

Expand Down Expand Up @@ -43,7 +43,7 @@ articles, and such.
Submit Feedback
~~~~~~~~~~~~~~~

The best way to send feedback is to file an issue at https://github.com/sabricot/django-elasticsearch-dsl/issues.
The best way to send feedback is to file an issue at https://github.com/sabricot/django-opensearch-dsl/issues.

If you are proposing a feature:

Expand All @@ -55,17 +55,17 @@ If you are proposing a feature:
Get Started!
------------

Ready to contribute? Here's how to set up `django-elasticsearch-dsl` for local development.
Ready to contribute? Here's how to set up `django-opensearch-dsl` for local development.

1. Fork the `django-elasticsearch-dsl` repo on GitHub.
1. Fork the `django-opensearch-dsl` repo on GitHub.
2. Clone your fork locally::

$ git clone [email protected]:your_name_here/django-elasticsearch-dsl.git
$ git clone [email protected]:your_name_here/django-opensearch-dsl.git

3. Install your local copy into a virtualenv. Assuming you have virtualenvwrapper installed, this is how you set up your fork for local development::

$ mkvirtualenv django-elasticsearch-dsl
$ cd django-elasticsearch-dsl/
$ mkvirtualenv django-opensearch-dsl
$ cd django-opensearch-dsl/
$ python setup.py develop

4. Create a branch for local development::
Expand Down Expand Up @@ -101,6 +101,6 @@ Before you submit a pull request, check that it meets these guidelines:
your new functionality into a function with a docstring, and add the
feature to the list in README.rst.
3. The pull request should work for Python 2.7, and 3.4, and for PyPy. Check
https://github.com/django-es/django-elasticsearch-dsl/actions
https://github.com/django-es/django-opensearch-dsl/actions
and make sure that the tests pass for all supported Python versions.

2 changes: 1 addition & 1 deletion HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ History
~~~~~~~~~~~~~~~~~~
* Support for Django `DecimalField` #141
* Indexing speedup by using `parallel` indexing. #213.
Now you can pass `--parallel` or set `ELASTICSEARCH_DSL_PARALLEL`
Now you can pass `--parallel` or set `OPENSEARCH_DSL_PARALLEL`
in your settings to get indexing speed boost while indexing
through management command.
* Fixing name resolution in management command #206
Expand Down
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ include CONTRIBUTING.rst
include HISTORY.rst
include LICENSE
include README.rst
recursive-include django_elasticsearch_dsl *.html *.png *.gif *js *.css *jpg *jpeg *svg *py
recursive-include django_opensearch_dsl *.html *.png *.gif *js *.css *jpg *jpeg *svg *py
18 changes: 9 additions & 9 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
Django Elasticsearch DSL
========================

.. image:: https://github.com/django-es/django-elasticsearch-dsl/actions/workflows/ci.yml/badge.svg
:target: https://github.com/django-es/django-elasticsearch-dsl/actions/workflows/ci.yml
.. image:: https://codecov.io/gh/django-es/django-elasticsearch-dsl/coverage.svg?branch=master
:target: https://codecov.io/gh/django-es/django-elasticsearch-dsl
.. image:: https://badge.fury.io/py/django-elasticsearch-dsl.svg
:target: https://pypi.python.org/pypi/django-elasticsearch-dsl
.. image:: https://readthedocs.org/projects/django-elasticsearch-dsl/badge/?version=latest&style=flat
:target: https://django-elasticsearch-dsl.readthedocs.io/en/latest/
.. image:: https://github.com/django-es/django-opensearch-dsl/actions/workflows/ci.yml/badge.svg
:target: https://github.com/django-es/django-opensearch-dsl/actions/workflows/ci.yml
.. image:: https://codecov.io/gh/django-es/django-opensearch-dsl/coverage.svg?branch=master
:target: https://codecov.io/gh/django-es/django-opensearch-dsl
.. image:: https://badge.fury.io/py/django-opensearch-dsl.svg
:target: https://pypi.python.org/pypi/django-opensearch-dsl
.. image:: https://readthedocs.org/projects/django-opensearch-dsl/badge/?version=latest&style=flat
:target: https://django-opensearch-dsl.readthedocs.io/en/latest/

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

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from .indices import Index # noqa
from .fields import * # noqa

__version__ = '7.1.1'
__version__ = '2.0.0'


def autodiscover():
Expand Down
19 changes: 9 additions & 10 deletions django_elasticsearch_dsl/apps.py → django_opensearch_dsl/apps.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,35 @@
from django.apps import AppConfig
from django.conf import settings
from django.utils.module_loading import import_string

from elasticsearch_dsl.connections import connections
from opensearchpy.connection import connections


class DEDConfig(AppConfig):
name = 'django_elasticsearch_dsl'
verbose_name = "Django elasticsearch-dsl"
name = 'django_opensearch_dsl'
verbose_name = "Django opensearch-dsl"
signal_processor = None

def ready(self):
self.module.autodiscover()
connections.configure(**settings.ELASTICSEARCH_DSL)
connections.configure(**settings.OPENSEARCH_DSL)
# Setup the signal processor.
if not self.signal_processor:
signal_processor_path = getattr(
settings,
'ELASTICSEARCH_DSL_SIGNAL_PROCESSOR',
'django_elasticsearch_dsl.signals.RealTimeSignalProcessor'
'OPENSEARCH_DSL_SIGNAL_PROCESSOR',
'django_opensearch_dsl.signals.RealTimeSignalProcessor'
)
signal_processor_class = import_string(signal_processor_path)
self.signal_processor = signal_processor_class(connections)

@classmethod
def autosync_enabled(cls):
return getattr(settings, 'ELASTICSEARCH_DSL_AUTOSYNC', True)
return getattr(settings, 'OPENSEARCH_DSL_AUTOSYNC', True)

@classmethod
def default_index_settings(cls):
return getattr(settings, 'ELASTICSEARCH_DSL_INDEX_SETTINGS', {})
return getattr(settings, 'OPENSEARCH_DSL_INDEX_SETTINGS', {})

@classmethod
def auto_refresh_enabled(cls):
return getattr(settings, 'ELASTICSEARCH_DSL_AUTO_REFRESH', True)
return getattr(settings, 'OPENSEARCH_DSL_AUTO_REFRESH', True)
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

from django import VERSION as DJANGO_VERSION
from django.db import models
from elasticsearch.helpers import bulk, parallel_bulk
from elasticsearch_dsl import Document as DSLDocument
from opensearchpy.helpers import bulk, parallel_bulk
from opensearchpy import Document as DSLDocument
from six import iteritems

from .exceptions import ModelFieldNotMappedError
from .exceptions import ModelFieldNotMappedError, RedeclaredFieldError
from .fields import (
BooleanField,
DateField,
Expand Down Expand Up @@ -150,7 +150,7 @@ def prepare(self, instance):
@classmethod
def get_model_field_class_to_field_class(cls):
"""
Returns dict of relationship from model field class to elasticsearch
Returns dict of relationship from model field class to opensearch
field class

You may want to override this if you have model field class not included
Expand All @@ -161,7 +161,7 @@ def get_model_field_class_to_field_class(cls):
@classmethod
def to_field(cls, field_name, model_field):
"""
Returns the elasticsearch field instance appropriate for the model
Returns the opensearch field instance appropriate for the model
field class. This is a good place to hook into if you have more complex
model field to ES field logic
"""
Expand Down Expand Up @@ -200,7 +200,7 @@ def parallel_bulk(self, actions, **kwargs):
def generate_id(cls, object_instance):
"""
The default behavior is to use the Django object's pk (id) as the
elasticseach index id (_id). If needed, this method can be overloaded
opensearch index id (_id). If needed, this method can be overloaded
to change this default behavior.
"""
return object_instance.pk
Expand All @@ -219,10 +219,10 @@ def _get_actions(self, object_list, action):
for object_instance in object_list:
if action == 'delete' or self.should_index_object(object_instance):
yield self._prepare_action(object_instance, action)

def get_actions(self, object_list, action):
"""
Generate the elasticsearch payload.
Generate the opensearch payload.
"""
return self._get_actions(object_list, action)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
from types import MethodType

import django
from django.core.exceptions import ObjectDoesNotExist
from django.db import models
from django.db.models.fields.files import FieldFile

if django.VERSION < (4, 0):
from django.utils.encoding import force_text as force_str
else:
from django.utils.encoding import force_str
from django.utils.encoding import force_str
from django.utils.functional import Promise
from elasticsearch_dsl.field import (
from opensearchpy.helpers.field import (
Boolean,
Byte,
Completion,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from copy import deepcopy

from elasticsearch_dsl import Index as DSLIndex
from opensearchpy import Index as DSLIndex
from six import python_2_unicode_compatible

from .apps import DEDConfig
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
from __future__ import unicode_literals, absolute_import
from datetime import datetime

from elasticsearch_dsl import connections
from opensearchpy.connection import connections
from django.conf import settings
from django.core.management.base import BaseCommand, CommandError
from six.moves import input
from ...registries import registry


class Command(BaseCommand):
help = 'Manage elasticsearch index.'
help = 'Manage opensearch index.'

def __init__(self, *args, **kwargs):
super(Command, self).__init__(*args, **kwargs)
Expand All @@ -21,28 +21,28 @@ def add_arguments(self, parser):
metavar='app[.model]',
type=str,
nargs='*',
help="Specify the model or app to be updated in elasticsearch"
help="Specify the model or app to be updated in opensearch"
)
parser.add_argument(
'--create',
action='store_const',
dest='action',
const='create',
help="Create the indices in elasticsearch"
help="Create the indices in opensearch"
)
parser.add_argument(
'--populate',
action='store_const',
dest='action',
const='populate',
help="Populate elasticsearch indices with models data"
help="Populate opensearch indices with models data"
)
parser.add_argument(
'--delete',
action='store_const',
dest='action',
const='delete',
help="Delete the indices in elasticsearch"
help="Delete the indices in opensearch"
)
parser.add_argument(
'--rebuild',
Expand Down Expand Up @@ -84,7 +84,7 @@ def add_arguments(self, parser):
'--use-alias' args
"""
)
parser.set_defaults(parallel=getattr(settings, 'ELASTICSEARCH_DSL_PARALLEL', False))
parser.set_defaults(parallel=getattr(settings, 'OPENSEARCH_DSL_PARALLEL', False))
parser.add_argument(
'--refresh',
action='store_true',
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

from django.core.exceptions import ObjectDoesNotExist
from django.core.exceptions import ImproperlyConfigured
from elasticsearch_dsl import AttrDict
from opensearchpy import AttrDict
from six import itervalues, iterkeys, iteritems

from django_elasticsearch_dsl.exceptions import RedeclaredFieldError
from .apps import DEDConfig
from .exceptions import RedeclaredFieldError


class DocumentRegistry(object):
Expand Down Expand Up @@ -129,7 +129,7 @@ def delete_related(self, instance, **kwargs):

def update(self, instance, **kwargs):
"""
Update all the elasticsearch documents attached to this model (if their
Update all the opensearch documents attached to this model (if their
ignore_signals flag allows it)
"""
if not DEDConfig.autosync_enabled():
Expand All @@ -142,7 +142,7 @@ def update(self, instance, **kwargs):

def delete(self, instance, **kwargs):
"""
Delete all the elasticsearch documents attached to this model (if their
Delete all the opensearch documents attached to this model (if their
ignore_signals flag allows it)
"""
self.update(instance, action="delete", **kwargs)
Expand Down
Loading
Loading