GitHub - vintasoftware/django-zombodb: Easy Django integration with Elasticsearc...
source link: https://github.com/vintasoftware/django-zombodb
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
README.rst
django-zombodb
Easy Django integration with Elasticsearch through ZomboDB Postgres Extension. Thanks to ZomboDB, your Django models are synced with Elasticsearch after every transaction! Searching is also very simple: you can make Elasticsearch queries by just calling one of the search methods on your querysets. Couldn't be easier!
Documentation
The full documentation is at https://django-zombodb.readthedocs.io.
Requirements
- Python: 3.4, 3.5, 3.6, 3.7
- Django: 2.0, 2.1
Quickstart
- Install ZomboDB (instructions here)
- Install django-zombodb:
pip install django-zombodb
- Add the
SearchQuerySet
and theZomboDBIndex
to your model:
from django_zombodb.indexes import ZomboDBIndex from django_zombodb.querysets import SearchQuerySet class Restaurant(models.Model): name = models.TextField() objects = models.Manager.from_queryset(SearchQuerySet)() class Meta: indexes = [ ZomboDBIndex(fields=[ 'name', ]), ]
- Make the migrations:
python manage.py makemigrations
- Add
django_zombodb.operations.ZomboDBExtension()
as the first operation of the migration you've just created:
import django_zombodb.operations class Migration(migrations.Migration): dependencies = [ ('restaurants', '0001_initial'), ] operations = [ django_zombodb.operations.ZomboDBExtension(), # <<< here ]
- Run the migrations (Postgres user must be SUPERUSER to create the ZomboDB extension):
python manage.py migrate
- Done! Now you can make Elasticsearch queries directly from your model:
Restaurant.objects.filter(is_open=True).query_string_search("brazil* AND coffee~")
Full Example
Check https://github.com/vintasoftware/django-zombodb/tree/master/example
Running Tests
You need to have Elasticsearch and Postgres instances running on default ports. Then just do:
python runtests.py
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK