Skip to content

Commit 24b89ec

Browse files
[8.1] [DOCS] Fixes ES startup code block markdown
Co-authored-by: István Zoltán Szabó <[email protected]>
1 parent 04dbec1 commit 24b89ec

File tree

1 file changed

+85
-38
lines changed

1 file changed

+85
-38
lines changed

docs/guide/connecting.asciidoc

Lines changed: 85 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,15 @@ This page contains the information you need to connect the Client with {es}.
77
[[connect-ec]]
88
=== Connecting to Elastic Cloud
99

10-
https://www.elastic.co/guide/en/cloud/current/ec-getting-started.html[Elastic Cloud] is the easiest way to get started with Elasticsearch. When connecting to Elastic Cloud with the Python Elasticsearch client you should always use the `cloud_id` parameter to connect. You can find this value within the "Manage Deployment" page after you've created a cluster (look in the top-left if you're in Kibana).
10+
https://www.elastic.co/guide/en/cloud/current/ec-getting-started.html[Elastic Cloud]
11+
is the easiest way to get started with {es}. When connecting to Elastic Cloud
12+
with the Python {es} client you should always use the `cloud_id`
13+
parameter to connect. You can find this value within the "Manage Deployment"
14+
page after you've created a cluster (look in the top-left if you're in Kibana).
1115

12-
We recommend using a Cloud ID whenever possible because your client will be automatically configured for optimal use with Elastic Cloud including HTTPS and HTTP compression.
16+
We recommend using a Cloud ID whenever possible because your client will be
17+
automatically configured for optimal use with Elastic Cloud including HTTPS and
18+
HTTP compression.
1319

1420
[source,python]
1521
----
@@ -36,15 +42,22 @@ client.info()
3642
[[connect-self-managed-new]]
3743
=== Connecting to a self-managed cluster
3844

39-
By default Elasticsearch will start with security features like authentication and TLS enabled. To connect to the Elasticsearch cluster you'll need to configure the Python Elasticsearch client to use HTTPS with the generated CA certificate in order to make requests successfully.
45+
By default {es} will start with security features like authentication and TLS
46+
enabled. To connect to the {es} cluster you'll need to configure the Python {es}
47+
client to use HTTPS with the generated CA certificate in order to make requests
48+
successfully.
4049

41-
If you're just getting started with Elasticsearch we recommend reading the documentation on https://www.elastic.co/guide/en/elasticsearch/reference/current/settings.html[configuring] and https://www.elastic.co/guide/en/elasticsearch/reference/current/starting-elasticsearch.html[starting Elasticsearch] to ensure your cluster is running as expected.
50+
If you're just getting started with {es} we recommend reading the documentation
51+
on https://www.elastic.co/guide/en/elasticsearch/reference/current/settings.html[configuring]
52+
and
53+
https://www.elastic.co/guide/en/elasticsearch/reference/current/starting-elasticsearch.html[starting {es}]
54+
to ensure your cluster is running as expected.
4255

43-
When you start Elasticsearch for the first time you'll see a distinct block like the one below in the output from Elasticsearch (you may have to scroll up if it's been a while):
56+
When you start {es} for the first time you'll see a distinct block like the one
57+
below in the output from {es} (you may have to scroll up if it's been a while):
4458

45-
[source,sh]
46-
----
47-
\----------------------------------------------------------------------
59+
```sh
60+
----------------------------------------------------------------
4861
-> Elasticsearch security features have been automatically configured!
4962
-> Authentication is enabled and cluster connections are encrypted.
5063
@@ -54,21 +67,30 @@ When you start Elasticsearch for the first time you'll see a distinct block like
5467
-> HTTP CA certificate SHA-256 fingerprint:
5568
a52dd93511e8c6045e21f16654b77c9ee0f34aea26d9f40320b531c474676228
5669
...
57-
\----------------------------------------------------------------------
58-
----
70+
----------------------------------------------------------------
71+
```
5972

60-
Note down the `elastic` user password and HTTP CA fingerprint for the next sections. In the examples below they will be stored in the variables `ELASTIC_PASSWORD` and `CERT_FINGERPRINT` respectively.
73+
Note down the `elastic` user password and HTTP CA fingerprint for the next
74+
sections. In the examples below they will be stored in the variables
75+
`ELASTIC_PASSWORD` and `CERT_FINGERPRINT` respectively.
6176

62-
Depending on the circumstances there are two options for verifying the HTTPS connection, either verifying with the CA certificate itself or via the HTTP CA certificate fingerprint.
77+
Depending on the circumstances there are two options for verifying the HTTPS
78+
connection, either verifying with the CA certificate itself or via the HTTP CA
79+
certificate fingerprint.
6380

6481
[discrete]
6582
==== Verifying HTTPS with CA certificates
6683

67-
Using the `ca_certs` option is the default way the Python Elasticsearch client verifies an HTTPS connection.
84+
Using the `ca_certs` option is the default way the Python {es} client verifies
85+
an HTTPS connection.
6886

69-
The generated root CA certificate can be found in the `certs` directory in your Elasticsearch config location (`$ES_CONF_PATH/certs/http_ca.crt`). If you're running Elasticsearch in Docker there is https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html[additional documentation for retrieving the CA certificate].
87+
The generated root CA certificate can be found in the `certs` directory in your
88+
{es} config location (`$ES_CONF_PATH/certs/http_ca.crt`). If you're running {es}
89+
in Docker there is
90+
https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html[additional documentation for retrieving the CA certificate].
7091

71-
Once you have the `http_ca.crt` file somewhere accessible pass the path to the client via `ca_certs`:
92+
Once you have the `http_ca.crt` file somewhere accessible pass the path to the
93+
client via `ca_certs`:
7294

7395
[source,python]
7496
----
@@ -89,14 +111,20 @@ client.info()
89111
# {'name': 'instance-0000000000', 'cluster_name': ...}
90112
----
91113

92-
NOTE: If you don't specify `ca_certs` or `ssl_assert_fingerprint` then the https://certifiio.readthedocs.io[certifi package] will be used for `ca_certs` by default if available.
114+
NOTE: If you don't specify `ca_certs` or `ssl_assert_fingerprint` then the
115+
https://certifiio.readthedocs.io[certifi package] will be used for `ca_certs` by
116+
default if available.
93117

94118
[discrete]
95119
==== Verifying HTTPS with certificate fingerprints (Python 3.10 or later)
96120

97-
NOTE: Using this method **requires using Python 3.10 or later** and isn't available when using the `aiohttp` HTTP client library so can't be used with `AsyncElasticsearch`.
121+
NOTE: Using this method **requires using Python 3.10 or later** and isn't
122+
available when using the `aiohttp` HTTP client library so can't be used with
123+
`AsyncElasticsearch`.
98124

99-
This method of verifying the HTTPS connection takes advantage of the certificate fingerprint value noted down earlier. Take this SHA256 fingerprint value and pass it to the Python Elasticsearch client via `ssl_assert_fingerprint`:
125+
This method of verifying the HTTPS connection takes advantage of the certificate
126+
fingerprint value noted down earlier. Take this SHA256 fingerprint value and
127+
pass it to the Python {es} client via `ssl_assert_fingerprint`:
100128

101129
[source,python]
102130
----
@@ -121,14 +149,17 @@ client.info()
121149
# {'name': 'instance-0000000000', 'cluster_name': ...}
122150
----
123151

124-
The certificate fingerprint can be calculated using `openssl x509` with the certificate file:
152+
The certificate fingerprint can be calculated using `openssl x509` with the
153+
certificate file:
125154

126155
[source,sh]
127156
----
128157
openssl x509 -fingerprint -sha256 -noout -in /path/to/http_ca.crt
129158
----
130159

131-
If you don't have access to the generated CA file from Elasticsearch you can use the following script to output the root CA fingerprint of the Elasticsearch instance with `openssl s_client`:
160+
If you don't have access to the generated CA file from {es} you can use the
161+
following script to output the root CA fingerprint of the {es} instance with
162+
`openssl s_client`:
132163

133164
[source,sh]
134165
----
@@ -150,9 +181,11 @@ SHA256 Fingerprint=A5:2D:D9:35:11:E8:C6:04:5E:21:F1:66:54:B7:7C:9E:E0:F3:4A:EA:2
150181
[[connect-no-security]]
151182
=== Connecting without security enabled
152183

153-
WARNING: Running Elasticsearch without security enabled is not recommended.
184+
WARNING: Running {es} without security enabled is not recommended.
154185

155-
If your cluster is configured with https://www.elastic.co/guide/en/elasticsearch/reference/current/security-settings.html[security explicitly disabled] then you can connect via HTTP:
186+
If your cluster is configured with
187+
https://www.elastic.co/guide/en/elasticsearch/reference/current/security-settings.html[security explicitly disabled]
188+
then you can connect via HTTP:
156189

157190
[source,python]
158191
----
@@ -170,7 +203,11 @@ client.info()
170203
[[connect-url]]
171204
=== Connecting to multiple nodes
172205

173-
The Python Elasticsearch client supports sending API requests to multiple nodes in the cluster. This means that work will be more evenly spread across the cluster instead of hammering the same node over and over with requests. To configure the client with multiple nodes you can pass a list of URLs, each URL will be used as a separate node in the pool.
206+
The Python {es} client supports sending API requests to multiple nodes in the
207+
cluster. This means that work will be more evenly spread across the cluster
208+
instead of hammering the same node over and over with requests. To configure the
209+
client with multiple nodes you can pass a list of URLs, each URL will be used as
210+
a separate node in the pool.
174211

175212
[source,python]
176213
----
@@ -193,9 +230,12 @@ client = Elasticsearch(
193230
)
194231
----
195232

196-
By default nodes are selected using round-robin, but alternate node selection strategies can be configured with `node_selector_class` parameter.
233+
By default nodes are selected using round-robin, but alternate node selection
234+
strategies can be configured with `node_selector_class` parameter.
197235

198-
NOTE: If your Elasticsearch cluster is behind a load balancer like when using Elastic Cloud you won't need to configure multiple nodes. Instead use the load balancer host and port.
236+
NOTE: If your {es} cluster is behind a load balancer like when using Elastic
237+
Cloud you won't need to configure multiple nodes. Instead use the load balancer
238+
host and port.
199239

200240

201241
[discrete]
@@ -239,8 +279,8 @@ for i in range(10):
239279
[[auth-basic]]
240280
==== HTTP Basic authentication (Username and Password)
241281

242-
HTTP Basic authentication uses the `basic_auth` parameter by passing in a username and
243-
password within a tuple:
282+
HTTP Basic authentication uses the `basic_auth` parameter by passing in a
283+
username and password within a tuple:
244284

245285
[source,python]
246286
----
@@ -282,7 +322,7 @@ es = Elasticsearch(
282322

283323
You can configure the client to use {es}'s API Key for connecting to your
284324
cluster. Note that you need the values of `id` and `api_key` to
285-
[authenticate via an API Key](https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-create-api-key.html).
325+
https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-create-api-key.html[authenticate via an API Key].
286326

287327
[source,python]
288328
----
@@ -300,22 +340,29 @@ es = Elasticsearch(
300340
[[compatibility-mode]]
301341
=== Enabling the Compatibility Mode
302342

303-
The Elasticsearch server version 8.0 is introducing a new compatibility mode that allows you a smoother upgrade
304-
experience from 7 to 8. In a nutshell, you can use the latest 7.x Python Elasticsearch Elasticsearch client with
305-
an 8.x Elasticsearch server, giving more room to coordinate the upgrade of your codebase to the next major version.
343+
The {es} server version 8.0 is introducing a new compatibility mode that allows
344+
you a smoother upgrade experience from 7 to 8. In a nutshell, you can use the
345+
latest 7.x Python {es} {es} client with an 8.x {es} server, giving more room to
346+
coordinate the upgrade of your codebase to the next major version.
306347

307-
If you want to leverage this functionality, please make sure that you are using the latest 7.x Python Elasticsearch
308-
client and set the environment variable `ELASTIC_CLIENT_APIVERSIONING` to `true`. The client is handling the rest
309-
internally. For every 8.0 and beyond Python Elasticsearch client, you're all set! The compatibility mode
310-
is enabled by default.
348+
If you want to leverage this functionality, please make sure that you are using
349+
the latest 7.x Python {es} client and set the environment variable
350+
`ELASTIC_CLIENT_APIVERSIONING` to `true`. The client is handling the rest
351+
internally. For every 8.0 and beyond Python {es} client, you're all set! The
352+
compatibility mode is enabled by default.
311353

312354
[discrete]
313355
[[connecting-faas]]
314356
=== Using the Client in a Function-as-a-Service Environment
315357

316-
This section illustrates the best practices for leveraging the {es} client in a Function-as-a-Service (FaaS) environment.
317-
The most influential optimization is to initialize the client outside of the function, the global scope.
318-
This practice does not only improve performance but also enables background functionality as – for example –
358+
This section illustrates the best practices for leveraging the {es} client in a
359+
Function-as-a-Service (FaaS) environment.
360+
361+
The most influential optimization is to initialize the client outside of the
362+
function, the global scope.
363+
364+
This practice does not only improve performance but also enables background
365+
functionality as – for example –
319366
https://www.elastic.co/blog/elasticsearch-sniffing-best-practices-what-when-why-how[sniffing].
320367
The following examples provide a skeleton for the best practices.
321368

0 commit comments

Comments
 (0)