ES Client API reference

ClientArgs Class

class es_client.builder.ClientArgs(settings=['hosts', 'cloud_id', 'api_key', 'basic_auth', 'bearer_auth', 'opaque_id', 'headers', 'connections_per_node', 'http_compress', 'verify_certs', 'ca_certs', 'client_cert', 'client_key', 'ssl_assert_hostname', 'ssl_assert_fingerprint', 'ssl_version', 'ssl_context', 'ssl_show_warn', 'transport_class', 'request_timeout', 'node_class', 'node_pool_class', 'randomize_nodes_in_pool', 'node_selector_class', 'dead_node_backoff_factor', 'max_dead_node_backoff', 'serializer', 'serializers', 'default_mimetype', 'max_retries', 'retry_on_status', 'retry_on_timeout', 'sniff_on_start', 'sniff_before_requests', 'sniff_on_node_failures', 'sniff_timeout', 'min_delay_between_sniffing', 'sniffed_node_callback', 'meta_header', 'host_info_callback', '_transport'])

ClientArgs object

Updatable object that will contain arguments for connecting to Elasticsearch

_is_protocol = False
asdict() dict

Return as a dictionary

clear() None.  Remove all items from D.
copy() a shallow copy of D
fromkeys(value=None, /)

Create a new dictionary with keys from iterable and values set to value.

get(key, default=None, /)

Return the value for key if key is in the dictionary, else default.

items() a set-like object providing a view on D's items
keys() a set-like object providing a view on D's keys
pop(k[, d]) v, remove specified key and return the corresponding value.

If the key is not found, return the default if given; otherwise, raise a KeyError.

popitem()

Remove and return a (key, value) pair as a 2-tuple.

Pairs are returned in LIFO (last-in, first-out) order. Raises KeyError if the dict is empty.

setdefault(key, default=None, /)

Insert key with a value of default if key is not in the dictionary.

Return the value for key if key is in the dictionary, else default.

update([E, ]**F) None.  Update D from dict/iterable E and F.

If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

update_settings(config: dict)

Update individual settings from provided config dict

values() an object providing a view on D's values

OtherArgs Class

class es_client.builder.OtherArgs(settings=['master_only', 'skip_version_test', 'username', 'password', 'api_key'])

OtherArgs object

Updatable object that will contain arguments for connecting to Elasticsearch

_is_protocol = False
asdict() dict

Return as a dictionary

clear() None.  Remove all items from D.
copy() a shallow copy of D
fromkeys(value=None, /)

Create a new dictionary with keys from iterable and values set to value.

get(key, default=None, /)

Return the value for key if key is in the dictionary, else default.

items() a set-like object providing a view on D's items
keys() a set-like object providing a view on D's keys
pop(k[, d]) v, remove specified key and return the corresponding value.

If the key is not found, return the default if given; otherwise, raise a KeyError.

popitem()

Remove and return a (key, value) pair as a 2-tuple.

Pairs are returned in LIFO (last-in, first-out) order. Raises KeyError if the dict is empty.

setdefault(key, default=None, /)

Insert key with a value of default if key is not in the dictionary.

Return the value for key if key is in the dictionary, else default.

update([E, ]**F) None.  Update D from dict/iterable E and F.

If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

update_settings(config: dict)

Update individual settings from provided config dict

values() an object providing a view on D's values

Builder Class

class es_client.builder.Builder(configdict=None, configfile=None, autoconnect=False, version_min=(8, 0, 0), version_max=(8, 99, 99))
Parameters:
  • configdict (dict) – A configuration dictionary

  • configfile (str) – A YAML configuration file

  • autoconnect (bool) – Connect to client automatically

  • version_min (tuple) – Minimum acceptable version of Elasticsearch (major, minor, patch)

  • version_max (tuple) – Maximum acceptable version of Elasticsearch (major, minor, patch)

Build a client connection object out of settings from configfile or configdict.

If neither configfile nor configdict is provided, empty defaults will be used.

If both are provided, configdict will be used, and configfile ignored.

_check_api_key()

Create api_key tuple from other_args ['api_key'] subkeys id and api_key

Or if api_key subkey token is present, derive id and api_key from token

_check_basic_auth()

Create basic_auth tuple from username and password

_check_cloud_id()

Remove hosts key if cloud_id provided

_check_master()

If master_only is True and we are not connected to the elected master node, raise NotMaster

_check_ssl()

Use certifi if using ssl and ca_certs has not been specified.

_check_version()

Compare the Elasticsearch cluster version to min_version and max_version

_find_master()

Find out if we are connected to the elected master node

_get_client()

Instantiate the Elasticsearch object and populate client

client

The Elasticsearch client connection object

client_args

The ClientArgs object

config

The validated configuration, either from file or dict

connect()

Attempt connection and do post-connection checks

is_master

Am I connected to the elected master node?

master_only

Is node is elected master?

other_args

The OtherArgs object

test_connection()

Connect and execute Elasticsearch.info()

update_config()

Update object with values provided

validate()

Validate that what has been supplied is acceptable to attempt a connection

version_max

Assigned version_max

version_min

Assigned version_min

Builder Attribute Errata

client:

The Elasticsearch object is only created after passing all other tests, and if autoconnect is True, or connect() has been called.

is_master:

Initially set to None, this value is set automatically if autoconnect is True. It can otherwise be set by calling _find_master() after _get_client() has been called first.

Class Instantiation Flow

  1. Check to see if elasticsearch key is in the supplied raw_config dictionary. Log a warning about using defaults if it is not.

  2. Run _check_config() on raw_config

  3. Set instance attributes version_max and version_min with the provided values.

  4. Set instance attribute master_only to the value from raw_config

  5. Initialize instance attribute is_master with a None

  6. Set instance attribute skip_version_test to the value from raw_config

  7. Set instance attribute client_args to the value of raw_config['elasticsearch']['client']

  8. Execute _check_basic_auth() to build the basic_auth tuple, if username and password are not None.

  9. Execute _check_api_key() to build the api_key tuple, if the id and api_key sub-keys are not None.

  10. Execute _check_cloud_id() to ensure the client connects to the defined cloud_id rather than anything in hosts.

  11. Execute _check_ssl() to ensure we have at least the certifi signing certificates.

  12. If autoconnect is True:

    1. Execute _get_client() to finally build the Elasticsearch client object.

    2. Execute _check_version() and _check_master() as post-checks. Nothing will happen if these checks are not enabled in raw_config