Client Builder Class

class es_client.Builder(configdict=None, configfile=None, autoconnect=False, version_min=(8, 0, 0), version_max=(8, 99, 99))

Build a client 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.

Parameters:
  • configdict (dict) – See defaults to find acceptable values
  • configfile (str) – See defaults to find acceptable values
  • autoconnect (bool) – Connect to client automatically
Attr client:

Elasticsearch Client object

Attr master_only:
 

Check if node is elected master.

Attr is_master:

Connected to elected master?

Attr client_args:
 

Settings used to connect to Elasticsearch.

Attr other_args:
 

Settings apart from client_args (though some are used to build client_args)

_check_api_key()

Create api_key tuple from self.other_args[‘api_key’] subkeys id and api_key

_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 our acceptable versions

_find_master()

Find out if we are connected to the elected master node

_get_client()

Instantiate the Elasticsearch Client object and populate client

connect()

Attempt connection and do post-connection checks

test_connection()

Connect and execute elasticsearch8.Elasticsearch.info()

update_config()

Update object with values provided

validate()

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

Builder Attribute Errata

client:The Elasticsearch Client object is only created after passing all other tests, and if autoconnect is True
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 client object.
    2. Execute _check_version() and _check_master() as post-checks. Nothing will happen if these checks are not enabled in raw_config