elastalk

API Documentation

Simple Conveniences for Talking to Elasticsearch

elastalk.config

Make things work the way you want!

class elastalk.config.BlobConf(enabled: bool = None, excluded: Set[str] = <factory>, key: str = None)[source]

Bases: object

Define blobbing parameters.

__init__(enabled: bool = None, excluded: Set[str] = <factory>, key: str = None) → None
enabled = None

indicates whether or not blobbing is enabled.

exclude(*keys)[source]

Add to the set of excluded document keys.

Parameters

keys – the excluded document keys

excluded = None

the excluded top-level document keys

key = None

the key that stores blobbed values in packed documents

classmethod load(dict_: Dict) → elastalk.config.BlobConf[source]

Create an instance of the class from a dictionary.

Parameters

dict – the dictionary

Returns

the instance

class elastalk.config.ElastalkConf(seeds: Iterable[str] = <factory>, sniff_on_start: bool = True, sniff_on_connection_fail: bool = True, sniffer_timeout: int = 60, maxsize: int = 10, mapping_field_limit: int = 1000, blobs: elastalk.config.BlobConf = BlobConf(enabled=None, excluded=set(), key=None), indexes: Dict[str, elastalk.config.IndexConf] = <factory>)[source]

Bases: object

Configuration options for an Elastalk and the Elasticsearch client.

__init__(seeds: Iterable[str] = <factory>, sniff_on_start: bool = True, sniff_on_connection_fail: bool = True, sniffer_timeout: int = 60, maxsize: int = 10, mapping_field_limit: int = 1000, blobs: elastalk.config.BlobConf = BlobConf(enabled=None, excluded=set(), key=None), indexes: Dict[str, elastalk.config.IndexConf] = <factory>) → None
blob_exclusions[source]

Get the full set of top-level document properties that should be excluded from blobs for a given index. If you don’t supply the index parameter, the method returns the global exclusions.

Parameters

index – the name of the index

Returns

the set of excluded property names

blob_key(index: str = None) → str[source]

Get the configured document key for blobbed data. (If you don’t supply the index, the method returns the global configuration value. If there is no global configuration value, the method returns the default.)

Parameters

index – the name of the index

Returns

the blobbed data key

blobs = BlobConf(enabled=None, excluded=set(), key=None)

global BLOB behavior configuration

blobs_enabled[source]

Determine whether or not blobbing is enabled for an index.

Parameters

index – the name of the index

Returns

True if blobbing is enabled, otherwise False

from_object(o: str) → elastalk.config.ElastalkConf[source]

Update the configuration from an object.

Parameters

o – the configuration object

from_toml(toml_: pathlib.Path) → elastalk.config.ElastalkConf[source]

Update the configuration from a TOML configuration.

Parameters

toml – the path to the file or the TOML configuration string

indexes = None

index-specific configurations

mapping_field_limit = 1000

the maximum number of mapped fields

maxsize = 10

the maximum number of connections

seeds = None

the Elasticsearch seed hosts

sniff_on_connection_fail = True

Sniff when the connection fails?

sniff_on_start = True

Start sniffing on startup?

sniffer_timeout = 60

the sniffer timeout

exception elastalk.config.ElastalkConfigException[source]

Bases: Exception

Raised when a configuration error is detected.

class elastalk.config.IndexConf(blobs: elastalk.config.BlobConf = BlobConf(enabled=None, excluded=set(), key=None), mappings: str = None)[source]

Bases: object

Define index-specific configuration settings.

__init__(blobs: elastalk.config.BlobConf = BlobConf(enabled=None, excluded=set(), key=None), mappings: str = None) → None
blobs = BlobConf(enabled=None, excluded=set(), key=None)

blobbing configuration for the index

classmethod load(dict_: Dict) → elastalk.config.IndexConf[source]

Create an instance of the class from a dictionary.

Parameters

dict – the dictionary

Returns

the instance

mappings = None

the path to Elasticsearch mappings for the configuration

mappings_document(root: pathlib.Path = None) → dict[source]

Get the contents of the index mapping document (if one is defined).

Parameters

root – the root path that contains the document file

Returns

the index mapping document (or None if one isn’t defined)

elastalk.connect

Start a conversation with Elasticsearch!

class elastalk.connect.ElastalkConnection(config: elastalk.config.ElastalkConf = None)[source]

Bases: object

Defines an Elasticsearch environment.

__init__(config: elastalk.config.ElastalkConf = None)[source]
Parameters

config – the configuration

property client

Get the Elasticsearch client.

Returns

the Elasticsearch client

Raises

ElasticsearchConfigurationException – if there is an error in the current configuration

property config

Get the connection configuration.

Returns

the connection configuration

static default(cnx: Optional[elastalk.connect.ElastalkConnection] = None) → elastalk.connect.ElastalkConnection[source]

Set and/or retrieve the default connection object.

Parameters

cnx – Provide a new connection object if you want to change the default. Otherwise, leave this argument out to retrieve the current object.

Returns

the default connection object

pack(doc: Dict, index: str) → Dict[str, Any][source]

Convert a document object into a BLOB document.

Parameters
  • doc – the original document object

  • index – the name of the index (This is optional, but if you supply it the behavior configured for the index can be used.)

Returns

the BLOB document

reset()[source]

Reset the connection.

unpack(doc: Dict, index: str = None) → Dict[source]

Convert a packed document to its original form.

Parameters
  • doc – the packed document

  • index – the name of the index for which the packed document came

Returns

the unpacked document

class elastalk.connect.ElastalkMixin[source]

Bases: object

Mix this into your class to get easy access to the Elasticsearch client.

property es

Get the Elasticsearch client.

property es_cnx

Get the Elastalk connection object.

Returns

the Elastalk connection object

elastalk.seed

Prepare your Elasticsearch store with seed data!

elastalk.seed.seed(root: str, config: str = 'config.toml', force: bool = False)[source]

Populate an Elasticsearch instance with seed data.

Parameters
  • root – the root directory that contains the seed data

  • config – the path to the configuration

  • force – delete existing indexes and replace them with seed data

Raises
  • FileNotFoundError – if the path does not exist

  • NotADirectoryError – if the path is not a directory

elastalk.version

This module contains project version information.