Package documentation

The djangoes package contains a simple way to integrate ElasticSearch.

This package mimics the behavior of the Django database configuration layer, using project settings and a global connections handler.

connections

Module-level attribute, instance of ConnectionHandler.

It can be considered as a singleton: it is the default connections handler to use with djangoes. It is instantiated at import with the default arguments.

Therefore, this object will automatically use the settings of your django project: ES_SERVERS and ES_INDICES.

class ConnectionHandler(servers=None, indices=None)

Handle connections to ElasticSearch.

Based on django.db.utils.ConnectionHandler, it aims to be an interface to integrate ElasticSearch connections in the same way database connections are integrated in Django.

However, instead of relaying on one setting variable, it needs two:

  • servers: ElasticSearch clusters connections settings (host, port, etc.)
  • indices: indices (or indexes) settings (name, aliases, analyzers, etc.)

These two will be defined in the django project settings with ES_SERVERS and ES_INDICES.

all()

Return all configured connection object.

It is a shortcut method to get all connections instead of manually doing a list-comprehension each time all connections are needed.

ensure_index_defaults(alias)

Put the defaults into the settings dictionary for alias.

ensure_server_defaults(alias)

Put the defaults into the settings dictionary for alias.

get_server_indices(server)

Prepare and return a given server’s indices settings.

Do not validate if the given server is available in self.servers: it is expected to find an INDICES key into server and that is all.

It is expected to find indices configured with the same name in self.indices.

load_backend(alias)

Prepare and load a backend for the given alias.

prepare_index_test_settings(alias)

Make sure the test settings are available in TEST.

prepare_server_test_settings(alias)

Make sure the test settings are available in TEST.