Django Inelastic Models¶
Introduction¶
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.
Compatibility¶
The following compatibility matrix summarizes supported versions of the Elasticsearch engine.
ES 1.X |
ES 2.X |
ES 5.X |
ES 6.X |
ES 7.X |
ES 8.X |
|
---|---|---|---|---|---|---|
1.0 |
Y |
N |
N |
N |
N |
N |
1.1 |
Y |
N |
N |
N |
N |
N |
1.2 |
N |
Y |
N |
N |
N |
N |
7.0 |
N |
N |
? [1] |
? [1] |
Y |
? [1] |
8.0 |
N |
N |
N |
N |
N |
Y |
Releases prior to 7.0 unofficially supported a variety of Django release series and did not explicitly indicate supported combinations. No official support or guidance is given for these releases.
Django 3.2 |
Django 4.2 |
|
---|---|---|
7.0 |
Y |
N |
8.0 |
Y |
planned |
Usage¶
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
}
}
},
Tests¶
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.