Environment Variables¶
Beginning in version 8.12, es_client allows you to use environment variables to configure settings without needing to specify a command-line option or a configuration file option.
This should prove exceptionally useful in containerized applications like Kubernetes or Docker.
Usage¶
A configuration file example:
elasticsearch:
client:
hosts: http://127.0.0.1:9200
other_settings:
username: user
password: pass
Which would be run as follows:
myapp.py --config /path/to/config.yml
or a command-line example:
myapp.py --hosts http://127.0.0.1:9200 --username user --password pass
Can both be executed with no configuration file and no command-line options as follows:
ESCLIENT_HOSTS=http://127.0.0.1:9200 ESCLIENT_USERNAME=user ESCLIENT_PASSWORD=pass myapp.py
In Kubernetes or Docker based applications, these environment variables can be set in advance, making the program call exceptionally clean. Of course, you’re still welcome to use a configuration file, but identify it with an environment variable:
ESCLIENT_CONFIG=/path/to/config.yml myapp.py
List of Environment Variables¶
Configuration File |
Command-Line |
Environment Variable |
---|---|---|
|
ESCLIENT_CONFIG |
|
hosts |
|
|
cloud_id |
|
ESCLIENT_CLOUD_ID |
token |
|
ESCLIENT_API_TOKEN |
id |
|
ESCLIENT_ID |
api_key |
|
ESCLIENT_API_KEY |
username |
|
ESCLIENT_USERNAME |
password |
|
ESCLIENT_PASSWORD |
request_timeout |
|
ESCLIENT_REQUEST_TIMEOUT |
verify_certs |
|
|
ca_certs |
|
ESCLIENT_CA_CERTS |
client_cert |
|
ESCLIENT_CLIENT_CERT |
client_key |
|
ESCLIENT_CLIENT_KEY |
loglevel |
|
ESCLIENT_LOGLEVEL |
logfile |
|
ESCLIENT_LOGFILE |
logformat |
|
ESCLIENT_LOGFORMAT |
Configuration File |
Command-Line |
Environment Variable |
---|---|---|
blacklist |
|
|
master_only |
|
|
skip_version_test |
|
|
bearer_auth |
|
ESCLIENT_BEARER_AUTH |
opaque_id |
|
ESCLIENT_OPAQUE_ID |
http_compress |
|
|
ssl_version |
|
ESCLIENT_SSL_VERSION |
ssl_assert_hostname |
|
ESCLIENT_SSL_ASSERT_HOSTNAME |
ssl_assert_fingerprint |
|
ESCLIENT_SSL_ASSERT_FINGERPRINT |
Settings With Multiple Values¶
Configuration File |
Command-Line |
Environment Variable |
---|---|---|
hosts |
|
ESCLIENT_HOSTS |
blacklist |
|
ESCLIENT_BLACKLIST |
Where multiple values are permitted, as with the hosts
and blacklist
settings, this is done
by simply specifying multiple values within quotes, e.g.
ESCLIENT_HOSTS="http://127.0.0.1:9200 http://localhost:9200"
This will automatically expand into an array of values:
config: {'client': {'hosts': ['http://127.0.0.1:9200', 'http://localhost:9200']}}...
Settings With Boolean Values¶
Configuration File |
Command-Line |
Environment Variable |
---|---|---|
verify_certs |
|
ESCLIENT_VERIFY_CERTS |
master_only |
|
ESCLIENT_MASTER_ONLY |
skip_version_test |
|
ESCLIENT_SKIP_VERSION_TEST |
http_compress |
|
ESCLIENT_HTTP_COMPRESS |
Where boolean values are accepted, as with the verify_certs setting, this is done with any acceptable boolean-eque value, e.g. 0, F, False for false values, or 1, T, True for true values:
ESCLIENT_MASTER_ONLY=true
ESCLIENT_MASTER_ONLY=T
ESCLIENT_MASTER_ONLY=1
Results in:
'other_settings': {'master_only': True,...
While:
ESCLIENT_MASTER_ONLY=false
ESCLIENT_MASTER_ONLY=F
ESCLIENT_MASTER_ONLY=0
Results in:
'other_settings': {'master_only': False,...
NOTE: All string-based booleans are case-insensitive.
True |
False |
---|---|
1 |
0 |
True, TRUE, true |
False, FALSE, false |
T, t |
F, f |