Elasticsearch configuration using microcosm wiring.
-
Provides a
microcosm
compatibleElasticsearch
client- Support vanilla Elasticsearch 6.x
- Support standard credentials and signed requests for AWS Elasticsearch
-
Includes an implementation of a persistence
Store
using Elasticsarch
See fixtures.py
for a minimal example of how to define an index, some models, a store and search index.
Starting with version 6 ElasticSearch removed support for multiple mapping types per index.
For applications that need polymorphic types within the same index, microcosm-elasticsearch
enables customization
of the doctype
field and instantiation of an apropriate Model
based on this field (which defaults to the lowercased
model class name.
For example, with this model defintion:
from elasticsearch_dsl.field import Text
from microcosm_elasticsearch import Model
class Person(Model):
first = Text()
last = Text()
person_store.create(Person(first="William", last="The Conqueror"))
The resulting record in ElasticSearch will look like:
{
"first": "William",
"last": "The Conqueror",
"doctype": "person"
}
And querying store.search()
will return an instance of Person
(vs Hit
) for this record.
Unit tests depend on a running instance of Elasticsearch:
-
Bring up the ES with
docker-compose
:docker-compose up -d
-
Run tests:
nosetests
When using vanilla Elasticsearch, set:
config.elasticsearch_client.host = localhost
config.elasticsearch_client.username = elastic
config.elasticsearch_client.password = changeme
When using with an AWS Elasticsearch instance, set the usual AWS_*
variables and use:
config.elasticsearch_client.host = some-host-name
config.elasticsearch_client.use_aws4auth = 'true'