Registry / web-framework / django-elasticsearch-dsl-drf

django-elasticsearch-dsl-drf

JSON →
library0.22.5pypypiunverified

A Django REST framework integration for Elasticsearch DSL. Provides filtering, sorting, searching, faceted search, and more. Current version 0.22.5 (July 2022). Releases are sporadic, with many features stable.

pip install django-elasticsearch-dsl-drf
INSTALL
IMPORT
SIG · DJANGO-ELASTICSEAR
D
django-elasticsearch-dsl-drf
web-frameworkpythonv0.22.5
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

DocumentViewSet
from django_elasticsearch_dsl_drf.viewsets import DocumentViewSet
from django_elasticsearch_dsl_drf.viewsets import DocumentViewSet

Basic setup: configure Elasticsearch, define a document, create a DocumentViewSet with filter backends, and register a router.

# settings.py INSTALLED_APPS = [ ... 'django_elasticsearch_dsl', 'django_elasticsearch_dsl_drf', ] ELASTICSEARCH_DSL = { 'default': { 'hosts': 'localhost:9200' }, } # documents.py from django_elasticsearch_dsl import Document, Index from myapp.models import MyModel PUBLISHED_INDEX = Index('my_models') PUBLISHED_INDEX.settings( number_of_shards=1, number_of_replicas=0 ) @PUBLISHED_INDEX.doc_type def MyModelDocument(Document): class Django: model = MyModel fields = [ 'id', 'title', 'description', ] # views.py from django_elasticsearch_dsl_drf.viewsets import DocumentViewSet from django_elasticsearch_dsl_drf.filter_backends import ( FilteringFilterBackend, SearchFilterBackend, OrderingFilterBackend, ) from .documents import MyModelDocument from .serializers import MyModelSerializer class MyModelDocumentViewSet(DocumentViewSet): document = MyModelDocument serializer_class = MyModelSerializer filter_backends = [ FilteringFilterBackend, SearchFilterBackend, OrderingFilterBackend, ] search_fields = ('title', 'description') filter_fields = { 'title': 'title', } ordering_fields = { 'id': 'id', } # urls.py from django.urls import path, include from rest_framework.routers import DefaultRouter from .views import MyModelDocumentViewSet router = DefaultRouter() router.register(r'my-models', MyModelDocumentViewSet, basename='mymodel') urlpatterns = [ ... path('api/', include(router.urls)), ]
Debug
Known issues
breakingVersion 0.21 dropped support for Python 2.7, 3.5 and Django 1.11, 2.0, 2.1. Upgrading from <0.21 requires Python 3.6+ and Django 2.2+.
fix
Ensure your environment uses Python 3.6+ and Django 2.2+.
affects: >=0.21
gotchaThe `Elasticsearch` client version must be compatible. The library uses `elasticsearch-dsl` which may require `elasticsearch<7.14` for certain versions. Incompatible client versions cause connection errors.
fix
Pin `elasticsearch>=7.0,<7.14` if using older versions of the library, or check compatibility matrix.
affects: all
deprecatedThe `FacetedFilterSearchFilterBackend` was added in 0.22.3 but may be unstable; consider using `FilteringFilterBackend` with `faceted` options.
fix
Refer to documentation for proper usage; test thoroughly.
affects: >=0.22.3
gotcha`EmptySearch` may cause `count` to return 0 if not handled (fixed in 0.22.5). If you see incorrect counts, update to 0.22.5 or later.
fix
Upgrade to >=0.22.5 or manually handle `EmptySearch` in your backend.
affects: <0.22.5
Upgrade
Version history
0.22.5latest on PyPI · released Jul 3, 2022
Audit
Dependencies
djangorequiredCore dependency
djangorestframeworkrequiredRequired for DRF integration
elasticsearch-dslrequiredRequired for Elasticsearch DSL interaction
elasticsearchrequiredRequired for low-level Elasticsearch client (usually elasticsearch<7.14 for compatibility)
Agent activity
11 hits · last 30 days
node
8
Amazon
1
Resources
django-elasticsearch-dsl-drf — pip install django-elasticsearch-dsl-drf · libregistry