Transport classes¶
List of transport classes that can be used, simply import your choice and pass
it to the constructor of Elasticsearch
as
connection_class. Note that the
RequestsHttpConnection
requires requests
to be installed.
For example to use the requests
-based connection just import it and use it:
from elasticsearch import Elasticsearch, RequestsHttpConnection
es = Elasticsearch(connection_class=RequestsHttpConnection)
The default connection class is based on urllib3
which is more performant
and lightweight than the optional requests
-based class. Only use
RequestsHttpConnection
if you have need of any of requests
advanced
features like custom auth plugins etc.
Product check on first request¶
Starting in v7.14.0 the client performs a required product check before the first API call is executed. This product check allows the client to establish that it’s communicating with a supported Elasticsearch cluster.
The product check requires a single HTTP request to the info
API. In
most cases this request will succeed quickly and then no further product
check HTTP requests will be sent.
The product check will verify that the X-Elastic-Product: Elasticsearch
HTTP header is being sent or if the info
API indicates a supported
distribution of Elasticsearch.
If the client detects that it’s not connected to a supported distribution of
Elasticsearch the UnsupportedProductError
exception will be raised.
In previous versions of Elasticsearch the info
API required additional
permissions so if an authentication or authorization error is raised during
the product check then an ElasticsearchWarning
is raised and the client
proceeds normally.
Connection¶
- class elasticsearch.connection.Connection(host='localhost', port=None, use_ssl=False, url_prefix='', timeout=10, headers=None, http_compress=None, cloud_id=None, api_key=None, opaque_id=None, meta_header=True, **kwargs)¶
Class responsible for maintaining a connection to an Elasticsearch node. It holds persistent connection pool to it and it’s main interface (perform_request) is thread-safe.
Also responsible for logging.
- Parameters
host – hostname of the node (default: localhost)
port – port to use (integer, default: 9200)
use_ssl – use ssl for the connection if True
url_prefix – optional url prefix for elasticsearch
timeout – default timeout in seconds (float, default: 10)
http_compress – Use gzip compression
cloud_id – The Cloud ID from ElasticCloud. Convenient way to connect to cloud instances.
opaque_id – Send this value in the ‘X-Opaque-Id’ HTTP header For tracing all requests made by this transport.
Urllib3HttpConnection¶
- class elasticsearch.connection.Urllib3HttpConnection(host='localhost', port=None, http_auth=None, use_ssl=False, verify_certs=<object object>, ssl_show_warn=<object object>, ca_certs=None, client_cert=None, client_key=None, ssl_version=None, ssl_assert_hostname=None, ssl_assert_fingerprint=None, maxsize=10, headers=None, ssl_context=None, http_compress=None, cloud_id=None, api_key=None, opaque_id=None, **kwargs)¶
Default connection class using the urllib3 library and the http protocol.
- Parameters
host – hostname of the node (default: localhost)
port – port to use (integer, default: 9200)
url_prefix – optional url prefix for elasticsearch
timeout – default timeout in seconds (float, default: 10)
http_auth – optional http auth information as either ‘:’ separated string or a tuple
use_ssl – use ssl for the connection if True
verify_certs – whether to verify SSL certificates
ssl_show_warn – show warning when verify certs is disabled
ca_certs – optional path to CA bundle. See https://urllib3.readthedocs.io/en/latest/security.html#using-certifi-with-urllib3 for instructions how to get default set
client_cert – path to the file containing the private key and the certificate, or cert only if using client_key
client_key – path to the file containing the private key if using separate cert and key files (client_cert will contain only the cert)
ssl_version – version of the SSL protocol to use. Choices are: SSLv23 (default) SSLv2 SSLv3 TLSv1 (see
PROTOCOL_*
constants in thessl
module for exact options for your environment).ssl_assert_hostname – use hostname verification if not False
ssl_assert_fingerprint – verify the supplied certificate fingerprint if not None
maxsize – the number of connections which will be kept open to this host. See https://urllib3.readthedocs.io/en/1.4/pools.html#api for more information.
headers – any custom http headers to be add to requests
http_compress – Use gzip compression
cloud_id – The Cloud ID from ElasticCloud. Convenient way to connect to cloud instances. Other host connection params will be ignored.
api_key – optional API Key authentication as either base64 encoded string or a tuple.
opaque_id – Send this value in the ‘X-Opaque-Id’ HTTP header For tracing all requests made by this transport.
RequestsHttpConnection¶
- class elasticsearch.connection.RequestsHttpConnection(host='localhost', port=None, http_auth=None, use_ssl=False, verify_certs=True, ssl_show_warn=True, ca_certs=None, client_cert=None, client_key=None, headers=None, http_compress=None, cloud_id=None, api_key=None, opaque_id=None, **kwargs)¶
Connection using the requests library.
- Parameters
http_auth – optional http auth information as either ‘:’ separated string or a tuple. Any value will be passed into requests as auth.
use_ssl – use ssl for the connection if True
verify_certs – whether to verify SSL certificates
ssl_show_warn – show warning when verify certs is disabled
ca_certs – optional path to CA bundle. By default standard requests’ bundle will be used.
client_cert – path to the file containing the private key and the certificate, or cert only if using client_key
client_key – path to the file containing the private key if using separate cert and key files (client_cert will contain only the cert)
headers – any custom http headers to be add to requests
http_compress – Use gzip compression
cloud_id – The Cloud ID from ElasticCloud. Convenient way to connect to cloud instances. Other host connection params will be ignored.
api_key – optional API Key authentication as either base64 encoded string or a tuple.
opaque_id – Send this value in the ‘X-Opaque-Id’ HTTP header For tracing all requests made by this transport.