{"id":26903,"library":"django-elasticsearch-dsl-drf","title":"Django Elasticsearch DSL DRF","description":"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.","status":"maintenance","version":"0.22.5","language":"python","source_language":"en","source_url":"https://github.com/barseghyanartur/django-elasticsearch-dsl-drf","tags":["django","elasticsearch","rest-framework","search","filtering"],"install":[{"cmd":"pip install django-elasticsearch-dsl-drf","lang":"bash","label":"Latest release"}],"dependencies":[{"reason":"Core dependency","package":"django","optional":false},{"reason":"Required for DRF integration","package":"djangorestframework","optional":false},{"reason":"Required for Elasticsearch DSL interaction","package":"elasticsearch-dsl","optional":false},{"reason":"Required for low-level Elasticsearch client (usually elasticsearch<7.14 for compatibility)","package":"elasticsearch","optional":false}],"imports":[{"note":"Direct import of viewsets from top-level package fails.","wrong":"from django_elasticsearch_dsl_drf import DocumentViewSet","symbol":"DocumentViewSet","correct":"from django_elasticsearch_dsl_drf.viewsets import DocumentViewSet"},{"note":"","wrong":"","symbol":"BackendFilter","correct":"from django_elasticsearch_dsl_drf.filter_backends import FilteringFilterBackend"}],"quickstart":{"code":"# settings.py\nINSTALLED_APPS = [\n    ...\n    'django_elasticsearch_dsl',\n    'django_elasticsearch_dsl_drf',\n]\n\nELASTICSEARCH_DSL = {\n    'default': {\n        'hosts': 'localhost:9200'\n    },\n}\n\n# documents.py\nfrom django_elasticsearch_dsl import Document, Index\nfrom myapp.models import MyModel\n\nPUBLISHED_INDEX = Index('my_models')\nPUBLISHED_INDEX.settings(\n    number_of_shards=1,\n    number_of_replicas=0\n)\n\n@PUBLISHED_INDEX.doc_type\ndef MyModelDocument(Document):\n    class Django:\n        model = MyModel\n        fields = [\n            'id',\n            'title',\n            'description',\n        ]\n\n# views.py\nfrom django_elasticsearch_dsl_drf.viewsets import DocumentViewSet\nfrom django_elasticsearch_dsl_drf.filter_backends import (\n    FilteringFilterBackend,\n    SearchFilterBackend,\n    OrderingFilterBackend,\n)\nfrom .documents import MyModelDocument\nfrom .serializers import MyModelSerializer\n\nclass MyModelDocumentViewSet(DocumentViewSet):\n    document = MyModelDocument\n    serializer_class = MyModelSerializer\n    filter_backends = [\n        FilteringFilterBackend,\n        SearchFilterBackend,\n        OrderingFilterBackend,\n    ]\n    search_fields = ('title', 'description')\n    filter_fields = {\n        'title': 'title',\n    }\n    ordering_fields = {\n        'id': 'id',\n    }\n\n# urls.py\nfrom django.urls import path, include\nfrom rest_framework.routers import DefaultRouter\nfrom .views import MyModelDocumentViewSet\n\nrouter = DefaultRouter()\nrouter.register(r'my-models', MyModelDocumentViewSet, basename='mymodel')\n\nurlpatterns = [\n    ...\n    path('api/', include(router.urls)),\n]","lang":"python","description":"Basic setup: configure Elasticsearch, define a document, create a DocumentViewSet with filter backends, and register a router."},"warnings":[{"fix":"Ensure your environment uses Python 3.6+ and Django 2.2+.","message":"Version 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+.","severity":"breaking","affected_versions":">=0.21"},{"fix":"Pin `elasticsearch>=7.0,<7.14` if using older versions of the library, or check compatibility matrix.","message":"The `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.","severity":"gotcha","affected_versions":"all"},{"fix":"Refer to documentation for proper usage; test thoroughly.","message":"The `FacetedFilterSearchFilterBackend` was added in 0.22.3 but may be unstable; consider using `FilteringFilterBackend` with `faceted` options.","severity":"deprecated","affected_versions":">=0.22.3"},{"fix":"Upgrade to >=0.22.5 or manually handle `EmptySearch` in your backend.","message":"`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.","severity":"gotcha","affected_versions":"<0.22.5"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Use: from django_elasticsearch_dsl_drf.viewsets import DocumentViewSet","cause":"Trying to import DocumentViewSet from the top-level package instead of the viewsets submodule.","error":"ImportError: cannot import name 'DocumentViewSet' from 'django_elasticsearch_dsl_drf'"},{"fix":"Ensure Elasticsearch is running and that the installed elasticsearch-py version is compatible (e.g., elasticsearch<7.14 for older library versions).","cause":"Elasticsearch client version mismatch or server not running.","error":"elasticsearch.exceptions.ConnectionError: ConnectionError(('Connection aborted.', RemoteDisconnected('Remote end closed connection without response')))"},{"fix":"Add both to INSTALLED_APPS: 'django_elasticsearch_dsl', 'django_elasticsearch_dsl_drf'.","cause":"Missing 'django_elasticsearch_dsl' in INSTALLED_APPS before 'django_elasticsearch_dsl_drf'.","error":"ImproperlyConfigured: 'django_elasticsearch_dsl' is not listed in INSTALLED_APPS"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}