Integrate Elasticsearch DSL with Django REST framework.
Project description
Integrate django-elasticsearch-dsl with Django REST framework in the shortest way possible, with least efforts possible.
Package provides views, filter backends and other handy tools.
You are expected to use django-elasticsearch-dsl for defining your document models.
Prerequisites
Django 1.8, 1.9, 1.10 and 1.11.
Python 2.7, 3.4, 3.5, 3.6
Elasticsearch 2.x, 5.x
Dependencies
django-elasticsearch-dsl
djangorestframework
Installation
Install latest stable version from PyPI:
pip install django-elasticsearch-dsl-drf
or latest stable version from GitHub:
pip install https://github.com/barseghyanartur/django-elasticsearch-dsl-drf/archive/stable.tar.gz
Add rest_framework and django_elasticsearch_dsl to INSTALLED_APPS:
INSTALLED_APPS = ( # ... 'rest_framework', # REST framework 'django_elasticsearch_dsl', # Elasticsearch integration # ... )
Search
Query param name reserved for search is search. Make sure your models and documents do not have it as a field or attribute.
Multiple search terms are joined with OR.
Let’s assume we have a number of Book items with fields title, description and summary.
Search in all fields
Search in all fields (name, address, city, state_province and country) for word “reilly”.
http://127.0.0.1:8080/search/publisher/?search=reilly
Search a single term on specific field
In order to search in specific field (name) for term “reilly”, add the field name separated with | to the search term.
http://127.0.0.1:8080/search/publisher/?search=name|reilly
Search for multiple terms
In order to search for multiple terms “reilly”, “bloomsbury” add multiple search query params.
http://127.0.0.1:8080/search/publisher/?search=reilly&search=bloomsbury
Search for multiple terms in specific fields
In order to search for multiple terms “reilly”, “bloomsbury” in specific fields add multiple search query params and field names separated with | to each of the search terms.
http://127.0.0.1:8080/search/publisher/?search=name|reilly&search=city|london
Filtering
Supported lookups
Native
The following native (to Elasticsearch) filters/lookups are implemented:
term
terms
range
exists
prefix
wildcard
ids
Functional
The following functional (non-native to Elasticsearch, but common in Django) filters/lookups are implemented:
contains
in
gt
gte
lt
lte
startswith
endswith
isnull
exclude
Usage examples
See the example project for sample models/views/serializers.
Additionally, see:
Testing
Project is covered with tests.
To test with all supported Python/Django versions type:
tox
To test against specific environment, type:
tox -e py36-django110
To test just your working environment type:
./runtests.py
To run a single test in your working environment type:
./runtests.py src/django_elasticsearch_dsl_drf/tests/test_filtering.py
Or:
./manage.py test django_elasticsearch_dsl_drf.tests.test_ordering
It’s assumed that you have all the requirements installed. If not, first install the test requirements:
pip install -r examples/requirements/test.txt
Writing documentation
Keep the following hierarchy.
=====
title
=====
header
======
sub-header
----------
sub-sub-header
~~~~~~~~~~~~~~
sub-sub-sub-header
^^^^^^^^^^^^^^^^^^
sub-sub-sub-sub-header
++++++++++++++++++++++
sub-sub-sub-sub-sub-header
**************************
License
GPL 2.0/LGPL 2.1
Support
For any issues contact me at the e-mail given in the Author section.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django-elasticsearch-dsl-drf-0.1.6.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | aaae06bda287a55bad3b853a420654e4f9839fb209d2b75646f56e9eb3f53f10 |
|
MD5 | 7795a96e65fc7133722d97e55e287977 |
|
BLAKE2b-256 | 03acf85eef5b04be6c508ce47c2b6164f8f846e5fcfe4b61aed7ccba0d071f67 |
Hashes for django_elasticsearch_dsl_drf-0.1.6-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9e245ec1c2c10b59e9483aed3bdf3f56e06553c825a7702428c1bbcf24a49a9e |
|
MD5 | 7243bc139cc7d16e8922f2a72dfe91bb |
|
BLAKE2b-256 | 2c8ca097f9f4c92bf53f1e8a126dfe770e55fae84770645286f1b20d054d558b |