Client Builder Class¶
-
class
es_client.
Builder
(raw_config, autoconnect=True, version_min=(8, 0, 0), version_max=(8, 99, 99))¶ Parameters: Attr client: Elasticsearch Client
objectAttr master_only: Check if node is elected master.
Attr is_master: Connected to elected master?
Attr client_args: Shows what settings were used to connect to Elasticsearch.
-
_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_config
(config)¶ Ensure that the top-level key
elasticsearch
and its sub-keys,other_settings
andclient
are inconfig
before passing it toSchemaCheck
for value validation.
-
_check_master
()¶ If
master_only
is True and we are not connected to the elected master node, raiseNotMaster
-
_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 populateclient
-
get_version
()¶ Get the Elasticsearch version of the connected node
-
test_connection
()¶ Connect and execute
elasticsearch8.Elasticsearch.info()
-
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¶
Check to see if elasticsearch key is in the supplied
raw_config
dictionary. Log a warning about using defaults if it is not.Run
_check_config()
onraw_config
Set instance attributes
version_max
andversion_min
with the provided values.Set instance attribute
master_only
to the value fromraw_config
Initialize instance attribute
is_master
with a NoneSet instance attribute
skip_version_test
to the value fromraw_config
Set instance attribute
client_args
to the value ofraw_config['elasticsearch']['client']
Execute
_check_basic_auth()
to build thebasic_auth
tuple, ifusername
andpassword
are not None.Execute
_check_api_key()
to build theapi_key
tuple, if theid
andapi_key
sub-keys are not None.Execute
_check_cloud_id()
to ensure the client connects to the definedcloud_id
rather than anything inhosts
.Execute
_check_ssl()
to ensure we have at least the certifi signing certificates.If
autoconnect
is True:- Execute
_get_client()
to finally build theElasticsearch Client
client object. - Execute
_check_version()
and_check_master()
as post-checks. Nothing will happen if these checks are not enabled inraw_config
- Execute