This package provides a small library for declaratively specifying indexes for Django models using an Elasticsearch backend.
It requires Django, elasticsearch-dsl and an available Elasticsearch instance.
Add
inelastic_models
toINSTALLED_APPS
.Mixin the type
inelastic_models.indexes.SearchMixin
to your models.Implement a type
inelastic_models.indexes.Search
and bind it to models:from .models import Foo class FooIndex(Search): attribute_fields = ('foo', 'baz') FooIndex.bind_to_model(Foo)
You must define ELASTICSEARCH_CONNECTIONS
. Pass index and connection parameters
to the generated indices and the underlying Elasticsearch
instance via the
INDEX_OPTIONS
and CONNECTION_OPTIONS
mappings, respectively:
ELASTICSEARCH_CONNECTIONS = { 'default': { 'HOSTS': ['http://localhost:9200'], 'INDEX_NAME': 'inelastic_models', 'INDEX_OPTIONS': { 'number_of_replicas': 3 }, 'CONNECTION_OPTIONS': { 'timeout': 42, 'retry_on_timeout': True } } },
Run tests using the make
rule:
make test [venv=<path>] [python=<python executable name, e.g., 'python3.5'>]
It is assumed that you have and Elasticsearch index available at elasticsearch:9200
and that
virtualenv
available on your path.