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, serializers, 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, django_elasticsearch_dsl and django_elasticsearch_dsl_drf to INSTALLED_APPS:
INSTALLED_APPS = ( # ... 'rest_framework', # REST framework 'django_elasticsearch_dsl', # Elasticsearch integration 'django_elasticsearch_dsl_drf', # This app # ... )
Quick start
Perhaps the easiest way to get acquainted with django-elasticsearch-dsl-drf is to read the quick start tutorial.
See it as a guide of diving into integration of Elasticsearch with Django with very low knowledge entry level.
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
Find documents which contain the exact term specified in the field specified.
http://127.0.0.1:8080/search/books/?tags__term=education&tags__term=economy
terms
Find documents which contain any of the exact terms specified in the field specified.
range
Find documents where the field specified contains values (dates, numbers, or strings) in the range specified.
exists
Find documents where the field specified contains any non-null value.
prefix
Find documents where the field specified contains terms which begin with the exact prefix specified.
wildcard
Find documents where the field specified contains terms which match the pattern specified, where the pattern supports single character wildcards (?) and multi-character wildcards (*)
ids
Find documents with the specified type and IDs.
Functional
The following functional (non-native to Elasticsearch, but common in Django) filters/lookups are implemented:
contains
Case-insensitive containment test.
in
In a given list.
gt
Greater than.
gte
Greater than or equal to.
lt
Less than.
lte
Less than or equal to.
startswith
Case-sensitive starts-with.
endswith
Case-sensitive ends-with.
isnull
Takes either True or False.
exclude
Returns a new query set of containing objects that do not match the given lookup parameters.
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.7.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 01dd90c64fe2d96d3a6dd2c7482a5cb03fbf180f2d023a5e4f95dba9ce8ef23d |
|
MD5 | 90b1d9be31b0fca3ce7cdcb72a8f290e |
|
BLAKE2b-256 | 2911f2ddf377e92a7db0c6d8437c737ebdee939037bdf9118820f6678423871d |
Hashes for django_elasticsearch_dsl_drf-0.1.7-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2a2951def9fbeaf1f691d7b6a1f9ba1c0dfabd04bacbfc2a47799260c5f0a8ee |
|
MD5 | 7fd478f8edbd8cc119d10ffd4231013f |
|
BLAKE2b-256 | c0df72e8d9a31e44a7a6a4b541aa8c97854ce8716ed3269701f159a4aa59233d |