2013-09-24 16:58:37 +02:00
|
|
|
.. _connection_api:
|
|
|
|
|
|
2013-09-23 14:42:23 +02:00
|
|
|
Connection Layer API
|
|
|
|
|
====================
|
|
|
|
|
|
2015-12-09 11:32:43 -06:00
|
|
|
All of the classes responsible for handling the connection to the Elasticsearch
|
2013-09-24 15:49:38 +02:00
|
|
|
cluster. The default subclasses used can be overriden by passing parameters to the
|
|
|
|
|
:class:`~elasticsearch.Elasticsearch` class. All of the arguments to the client
|
|
|
|
|
will be passed on to :class:`~elasticsearch.Transport`,
|
|
|
|
|
:class:`~elasticsearch.ConnectionPool` and :class:`~elasticsearch.Connection`.
|
|
|
|
|
|
|
|
|
|
For example if you wanted to use your own implementation of the
|
|
|
|
|
:class:`~elasticsearch.ConnectionSelector` class you can just pass in the
|
2014-12-20 14:47:30 +01:00
|
|
|
``selector_class`` parameter.
|
|
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
|
|
:class:`~elasticsearch.ConnectionPool` and related options (like
|
|
|
|
|
``selector_class``) will only be used if more than one connection is defined.
|
|
|
|
|
Either directly or via the :ref:`sniffing` mechanism.
|
2013-09-24 15:49:38 +02:00
|
|
|
|
2013-09-23 14:42:23 +02:00
|
|
|
.. py:module:: elasticsearch
|
|
|
|
|
|
|
|
|
|
Transport
|
|
|
|
|
---------
|
|
|
|
|
|
2018-04-12 20:20:03 +02:00
|
|
|
.. autoclass:: Transport(hosts, connection_class=Urllib3HttpConnection, connection_pool_class=ConnectionPool, host_info_callback=construct_hosts_list, sniff_on_start=False, sniffer_timeout=None, sniff_on_connection_fail=False, serializer=JSONSerializer(), max_retries=3, ** kwargs)
|
2013-09-23 14:42:23 +02:00
|
|
|
:members:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Connection Pool
|
|
|
|
|
---------------
|
|
|
|
|
|
|
|
|
|
.. autoclass:: ConnectionPool(connections, dead_timeout=60, selector_class=RoundRobinSelector, randomize_hosts=True, ** kwargs)
|
|
|
|
|
:members:
|
|
|
|
|
|
|
|
|
|
|
2013-09-24 15:49:38 +02:00
|
|
|
Connection Selector
|
|
|
|
|
-------------------
|
|
|
|
|
|
|
|
|
|
.. autoclass:: ConnectionSelector(opts)
|
|
|
|
|
:members:
|
|
|
|
|
|
|
|
|
|
|
2014-11-11 03:20:16 +01:00
|
|
|
Urllib3HttpConnection (default connection_class)
|
|
|
|
|
------------------------------------------------
|
2013-09-23 14:42:23 +02:00
|
|
|
|
2018-03-04 15:09:40 -08:00
|
|
|
If you have complex SSL logic for connecting to Elasticsearch using an `SSLContext` object
|
|
|
|
|
might be more helpful. You can create one natively using the python SSL library with the
|
|
|
|
|
`create_default_context` (https://docs.python.org/3/library/ssl.html#ssl.create_default_context) method.
|
2017-08-16 21:39:32 -06:00
|
|
|
|
2017-12-28 12:08:55 -07:00
|
|
|
To create an `SSLContext` object you only need to use one of cafile, capath or cadata::
|
|
|
|
|
|
2018-03-04 15:09:40 -08:00
|
|
|
>>> from ssl import create_default_context
|
|
|
|
|
>>> context = create_default_context(cafile=None, capath=None, cadata=None)
|
2017-12-28 12:08:55 -07:00
|
|
|
|
|
|
|
|
* `cafile` is the path to your CA File
|
|
|
|
|
* `capath` is the directory of a collection of CA's
|
|
|
|
|
* `cadata` is either an ASCII string of one or more PEM-encoded certificates or a bytes-like object of DER-encoded certificates.
|
2017-08-16 21:39:32 -06:00
|
|
|
|
2018-03-04 15:09:40 -08:00
|
|
|
Please note that the use of SSLContext is only available for Urllib3.
|
|
|
|
|
|
2014-11-11 03:20:16 +01:00
|
|
|
.. autoclass:: Urllib3HttpConnection
|
2013-09-23 14:42:23 +02:00
|
|
|
:members:
|