Integrate your Django Project with Elastic App Search with ease.
Project description
Integrate your Django Project with Elastic App Search with ease.
Documentation
The full documentation is at https://django_elastic_appsearch.readthedocs.io.
Quickstart
Install Django Elastic App Search:
pip install django_elastic_appsearch
Add it to your INSTALLED_APPS:
INSTALLED_APPS = (
...
'django_elastic_appsearch',
...
)
Add the Elastic App Search URL and Key to your settings module:
APPSEARCH_URL = 'https://appsearch.base.url'
APPSEARCH_API_KEY = 'some_appsearch_api_token'
Configure the Django models you want to index to Elastic App Search. You can do this by inheriting from the AppSearchModel, and then setting some meta options.
AppsearchMeta.appsearch_engine_name - Defines which engine in your app search instance your model will be indexed to.
AppsearchMeta.appsearch_serialiser_class - Defines how your model object will be serialised when sent to your elastic app search instance. The serialiser and fields used here derives from Serpy, and you can use any of the serpy features like method fields.
Example:
from django_elastic_appsearch.orm import AppSearchModel
from django_elastic_appsearch import serialisers
class CarSerialiser(serialisers.AppSearchSerialiser):
full_name = serialisers.MethodField()
make = serialisers.StrField()
model = serialisers.StrField()
manufactured_year = serialisers.Field()
def get_full_name(self, instance):
return '{} {}'.format(make, model)
class Car(AppSearchModel):
class AppsearchMeta:
appsearch_engine_name = 'cars'
appsearch_serialiser_class = CarSerialiser
make = models.CharField(max_length=100)
model = models.CharField(max_length=100)
manufactured_year = models.CharField(max_length=4)
Then you can call index_to_appsearch and delete_from_appsearch from your model objects.
Send the car with id 25 to app search.
from mymodels import Car
car = Car.objects.get(id=25)
car.index_to_appsearch()
Delete the car with id 21 from app search.
from mymodels import Car
car = Car.objects.get(id=21)
car.delete_from_appsearch()
You can also call index_to_appsearch and delete_from_appsearch on QuerySets of AppSearchModel
Send all cars where the make is ‘Toyota’ to app search.
cars = Car.objects.filter(make='Toyota')
cars.index_to_appsearch()
Delete all cars where the make is ‘Saab’ from app search
cars = Car.objects.filter(make='Saab')
cars.delete_from_appsearch()
If you want to speficy custom managers which also has this functionality, you can inherit from django_elastic_appsearch.orm.AppSearchQuerySet
from django_elastic_appsearch.orm import AppSearchModel, AppSearchQuerySet
class MyCustomQuerySetManager(AppSearchQuerySet):
def my_custom_queryset_feature(self):
# Do Something cool
pass
class MyCustomModel(AppSearchModel):
field_1 = models.CharField(max_length=100)
# Set the custom manager
objects = MyCustomQuerySetManager.as_manager()
Running Tests
Does the code actually work?
source <YOURVIRTUALENV>/bin/activate (myenv) $ pip install tox (myenv) $ tox
Credits
Tools used in rendering this package:
History
0.1.0 (2019-07-26)
First release on PyPI.
0.2.2 (2019-07-29)
Bug fixes
Documentation improvements
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_elastic_appsearch-0.2.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | e53821b17083b9f12dccb6288b7bf531cddc9b7fdefca5981de5c3ccbe2540eb |
|
MD5 | 6db39913da9168c22d32513b10466e78 |
|
BLAKE2b-256 | 1376d621d6d122b622830ac55845cfa4f489685966ddc02d36ae416bcd7d0e26 |
Hashes for django_elastic_appsearch-0.2.2-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | de22262306d099c477cc191ae9d81f7d350bb69b19572a6edf77f0f00b8209e2 |
|
MD5 | 4c0e34176524201785cb2fb9d6c01b68 |
|
BLAKE2b-256 | 85531f6d48f32d5eda90eb03b41b1700ea610cb38d045707f138bbe2165868ee |