Skip to content

Commit b5a2439

Browse files
[Backport 8.13] Rename es to client in examples for consistency (#2499)
(cherry picked from commit 794341d) Co-authored-by: Iulia Feroli <[email protected]>
1 parent 98fb371 commit b5a2439

12 files changed

+80
-78
lines changed

docs/examples/3d1ff6097e2359f927c88c2ccdb36252.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
[source, python]
44
----
5-
resp = es.info()
5+
resp = client.info()
66
print(resp)
77
----

docs/guide/configuration.asciidoc

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ If you have your own CA bundle to use you can configure via the `ca_certs` param
2020

2121
[source,python]
2222
------------------------------------
23-
es = Elasticsearch(
23+
client = Elasticsearch(
2424
"https://...",
2525
ca_certs="/path/to/certs.pem"
2626
)
@@ -32,7 +32,7 @@ In Python 3.9 and earlier only the leaf certificate will be verified but in Pyth
3232

3333
[source,python]
3434
------------------------------------
35-
es = Elasticsearch(
35+
client = Elasticsearch(
3636
"https://...",
3737
ssl_assert_fingerprint=(
3838
"315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894edd3"
@@ -44,7 +44,7 @@ To disable certificate verification use the `verify_certs=False` parameter. This
4444

4545
[source,python]
4646
------------------------------------
47-
es = Elasticsearch(
47+
client = Elasticsearch(
4848
"https://...",
4949
verify_certs=False
5050
)
@@ -59,7 +59,7 @@ Configuring the minimum TLS version to connect to is done via the `ssl_version`
5959
------------------------------------
6060
import ssl
6161
62-
es = Elasticsearch(
62+
client = Elasticsearch(
6363
...,
6464
ssl_version=ssl.TLSVersion.TLSv1_2
6565
)
@@ -72,7 +72,7 @@ Elasticsearch can be configured to authenticate clients via TLS client certifica
7272

7373
[source,python]
7474
------------------------------------
75-
es = Elasticsearch(
75+
client = Elasticsearch(
7676
...,
7777
client_cert="/path/to/cert.pem",
7878
client_key="/path/to/key.pem",
@@ -93,7 +93,7 @@ import ssl
9393
ctx = ssl.create_default_context()
9494
ctx.load_verify_locations(...)
9595
96-
es = Elasticsearch(
96+
client = Elasticsearch(
9797
...,
9898
ssl_context=ctx
9999
)
@@ -110,7 +110,7 @@ the `Accept-Encoding: gzip` HTTP header. By default compression is disabled.
110110

111111
[source,python]
112112
------------------------------------
113-
es = Elasticsearch(
113+
client = Elasticsearch(
114114
...,
115115
http_compress=True # Enable compression!
116116
)
@@ -130,13 +130,13 @@ Setting `request_timeout` to `None` will disable timeouts.
130130

131131
[source,python]
132132
------------------------------------
133-
es = Elasticsearch(
133+
client = Elasticsearch(
134134
...,
135135
request_timeout=10 # 10 second timeout
136136
)
137137
138138
# Search request will timeout in 5 seconds
139-
es.options(request_timeout=5).search(...)
139+
client.options(request_timeout=5).search(...)
140140
------------------------------------
141141

142142
[discrete]
@@ -148,7 +148,7 @@ In the example below there are three different configurable timeouts for the `cl
148148

149149
[source,python]
150150
------------------------------------
151-
es.options(
151+
client.options(
152152
# Amount of time to wait for an HTTP response to start.
153153
request_timeout=30
154154
).cluster.health(
@@ -170,13 +170,13 @@ The maximum number of retries per request can be configured via the `max_retries
170170

171171
[source,python]
172172
------------------------------------
173-
es = Elasticsearch(
173+
client = Elasticsearch(
174174
...,
175175
max_retries=5
176176
)
177177
178178
# For this API request we disable retries with 'max_retries=0'
179-
es.options(max_retries=0).index(
179+
client.options(max_retries=0).index(
180180
index="blogs",
181181
document={
182182
"title": "..."
@@ -191,11 +191,11 @@ Connection errors are automatically retried if retries are enabled. Retrying req
191191

192192
[source,python]
193193
------------------------------------
194-
es = Elasticsearch(
194+
client = Elasticsearch(
195195
...,
196196
retry_on_timeout=True
197197
)
198-
es.options(retry_on_timeout=False).info()
198+
client.options(retry_on_timeout=False).info()
199199
------------------------------------
200200

201201
[discrete]
@@ -205,13 +205,13 @@ By default if retries are enabled `retry_on_status` is set to `(429, 502, 503, 5
205205

206206
[source,python]
207207
------------------------------------
208-
es = Elasticsearch(
208+
client = Elasticsearch(
209209
...,
210210
retry_on_status=()
211211
)
212212
213213
# Retry this API on '500 Internal Error' statuses
214-
es.options(retry_on_status=[500]).index(
214+
client.options(retry_on_status=[500]).index(
215215
index="blogs",
216216
document={
217217
"title": "..."
@@ -228,14 +228,14 @@ A good example where this is useful is setting up or cleaning up resources in a
228228

229229
[source,python]
230230
------------------------------------
231-
es = Elasticsearch(...)
231+
client = Elasticsearch(...)
232232
233233
# API request is robust against the index not existing:
234-
resp = es.options(ignore_status=404).indices.delete(index="delete-this")
234+
resp = client.options(ignore_status=404).indices.delete(index="delete-this")
235235
resp.meta.status # Can be either '2XX' or '404'
236236
237237
# API request is robust against the index already existing:
238-
resp = es.options(ignore_status=[400]).indices.create(
238+
resp = client.options(ignore_status=[400]).indices.create(
239239
index="create-this",
240240
mapping={
241241
"properties": {"field": {"type": "integer"}}
@@ -322,7 +322,7 @@ You can specify a node selector pattern via the `node_selector_class` parameter.
322322

323323
[source,python]
324324
------------------------------------
325-
es = Elasticsearch(
325+
client = Elasticsearch(
326326
...,
327327
node_selector_class="round_robin"
328328
)
@@ -337,7 +337,7 @@ from elastic_transport import NodeSelector
337337
class CustomSelector(NodeSelector):
338338
def select(nodes): ...
339339
340-
es = Elasticsearch(
340+
client = Elasticsearch(
341341
...,
342342
node_selector_class=CustomSelector
343343
)
@@ -374,7 +374,7 @@ class JsonSetSerializer(JsonSerializer):
374374
return list(data)
375375
return super().default(data)
376376
377-
es = Elasticsearch(
377+
client = Elasticsearch(
378378
...,
379379
# Serializers are a mapping of 'mimetype' to Serializer class.
380380
serializers={"application/json": JsonSetSerializer()}
@@ -397,7 +397,7 @@ For all of the built-in HTTP node implementations like `urllib3`, `requests`, an
397397
------------------------------------
398398
from elasticsearch import Elasticsearch
399399
400-
es = Elasticsearch(
400+
client = Elasticsearch(
401401
...,
402402
node_class="requests"
403403
)
@@ -413,7 +413,7 @@ from elastic_transport import Urllib3HttpNode
413413
class CustomHttpNode(Urllib3HttpNode):
414414
...
415415
416-
es = Elasticsearch(
416+
client = Elasticsearch(
417417
...
418418
node_class=CustomHttpNode
419419
)
@@ -426,7 +426,7 @@ Each node contains its own pool of HTTP connections to allow for concurrent requ
426426

427427
[source,python]
428428
------------------------------------
429-
es = Elasticsearch(
429+
client = Elasticsearch(
430430
...,
431431
connections_per_node=5
432432
)

docs/guide/connecting.asciidoc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -251,20 +251,20 @@ or via the per-request `.options()` method:
251251
from elasticsearch import Elasticsearch
252252
253253
# Authenticate from the constructor
254-
es = Elasticsearch(
254+
client = Elasticsearch(
255255
"https://localhost:9200",
256256
ca_certs="/path/to/http_ca.crt",
257257
basic_auth=("username", "password")
258258
)
259259
260260
# Authenticate via the .options() method:
261-
es.options(
261+
client.options(
262262
basic_auth=("username", "password")
263263
).indices.get(index="*")
264264
265265
# You can persist the authenticated client to use
266266
# later or use for multiple API calls:
267-
auth_client = es.options(api_key="api_key")
267+
auth_client = client.options(api_key="api_key")
268268
for i in range(10):
269269
auth_client.index(
270270
index="example-index",
@@ -285,7 +285,7 @@ username and password within a tuple:
285285
from elasticsearch import Elasticsearch
286286
287287
# Adds the HTTP header 'Authorization: Basic <base64 username:password>'
288-
es = Elasticsearch(
288+
client = Elasticsearch(
289289
"https://localhost:9200",
290290
ca_certs="/path/to/http_ca.crt",
291291
basic_auth=("username", "password")
@@ -307,7 +307,7 @@ and https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/security-ap
307307
from elasticsearch import Elasticsearch
308308
309309
# Adds the HTTP header 'Authorization: Bearer token-value'
310-
es = Elasticsearch(
310+
client = Elasticsearch(
311311
"https://localhost:9200",
312312
bearer_auth="token-value"
313313
)
@@ -328,7 +328,7 @@ or https://www.elastic.co/guide/en/kibana/current/api-keys.html#create-api-key[K
328328
from elasticsearch import Elasticsearch
329329
330330
# Adds the HTTP header 'Authorization: ApiKey <base64 api_key.id:api_key.api_key>'
331-
es = Elasticsearch(
331+
client = Elasticsearch(
332332
"https://localhost:9200",
333333
ca_certs="/path/to/http_ca.crt",
334334
api_key="api_key",

docs/guide/examples.asciidoc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ To index a document, you need to specify three pieces of information: `index`,
2222
----------------------------
2323
from datetime import datetime
2424
from elasticsearch import Elasticsearch
25-
es = Elasticsearch('https://localhost:9200')
25+
client = Elasticsearch('https://localhost:9200')
2626
2727
doc = {
2828
'author': 'author_name',
2929
'text': 'Interesting content...',
3030
'timestamp': datetime.now(),
3131
}
32-
resp = es.index(index="test-index", id=1, document=doc)
32+
resp = client.index(index="test-index", id=1, document=doc)
3333
print(resp['result'])
3434
----------------------------
3535

@@ -42,7 +42,7 @@ To get a document, you need to specify its `index` and `id`:
4242

4343
[source,py]
4444
----------------------------
45-
resp = es.get(index="test-index", id=1)
45+
resp = client.get(index="test-index", id=1)
4646
print(resp['_source'])
4747
----------------------------
4848

@@ -55,7 +55,7 @@ You can perform the refresh operation on an index:
5555

5656
[source,py]
5757
----------------------------
58-
es.indices.refresh(index="test-index")
58+
client.indices.refresh(index="test-index")
5959
----------------------------
6060

6161

@@ -67,7 +67,7 @@ The `search()` method returns results that are matching a query:
6767

6868
[source,py]
6969
----------------------------
70-
resp = es.search(index="test-index", query={"match_all": {}})
70+
resp = client.search(index="test-index", query={"match_all": {}})
7171
print("Got %d Hits:" % resp['hits']['total']['value'])
7272
for hit in resp['hits']['hits']:
7373
print("%(timestamp)s %(author)s: %(text)s" % hit["_source"])

docs/guide/integrations.asciidoc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ The opaque ID can be set via the `opaque_id` parameter via the client `.options(
2323

2424
[source,python]
2525
------------------------------------
26-
es = Elasticsearch(...)
27-
es.options(opaque_id="request-id-...").search(...)
26+
client = Elasticsearch(...)
27+
client.options(opaque_id="request-id-...").search(...)
2828
------------------------------------
2929

3030

@@ -41,8 +41,8 @@ If we write a script that has a type error like using `request_timeout` with a `
4141
# script.py
4242
from elasticsearch import Elasticsearch
4343
44-
es = Elasticsearch(...)
45-
es.options(
44+
client = Elasticsearch(...)
45+
client.options(
4646
request_timeout="5" # type error!
4747
).search(...)
4848

docs/guide/overview.asciidoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ Simple use-case:
4242
>>> from elasticsearch import Elasticsearch
4343
4444
# Connect to 'http://localhost:9200'
45-
>>> es = Elasticsearch("http://localhost:9200")
45+
>>> client = Elasticsearch("http://localhost:9200")
4646
4747
# Datetimes will be serialized:
48-
>>> es.index(index="my-index-000001", id=42, document={"any": "data", "timestamp": datetime.now()})
48+
>>> client.index(index="my-index-000001", id=42, document={"any": "data", "timestamp": datetime.now()})
4949
{'_id': '42', '_index': 'my-index-000001', '_type': 'test-type', '_version': 1, 'ok': True}
5050
5151
# ...but not deserialized
52-
>>> es.get(index="my-index-000001", id=42)['_source']
52+
>>> client.get(index="my-index-000001", id=42)['_source']
5353
{'any': 'data', 'timestamp': '2013-05-12T19:45:31.804229'}
5454
------------------------------------
5555

0 commit comments

Comments
 (0)