Skip to content

Commit 1c2d29c

Browse files
committed
replace es with client
1 parent f89871a commit 1c2d29c

File tree

5 files changed

+52
-52
lines changed

5 files changed

+52
-52
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: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -251,21 +251,21 @@ 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(
268-
api_key=("api-key-id", "api-key-secret")
267+
auth_client = client.options(
268+
api_key=("api-key")
269269
)
270270
for i in range(10):
271271
auth_client.index(
@@ -287,7 +287,7 @@ username and password within a tuple:
287287
from elasticsearch import Elasticsearch
288288
289289
# Adds the HTTP header 'Authorization: Basic <base64 username:password>'
290-
es = Elasticsearch(
290+
client = Elasticsearch(
291291
"https://localhost:9200",
292292
ca_certs="/path/to/http_ca.crt",
293293
basic_auth=("username", "password")
@@ -309,7 +309,7 @@ and https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/security-ap
309309
from elasticsearch import Elasticsearch
310310
311311
# Adds the HTTP header 'Authorization: Bearer token-value'
312-
es = Elasticsearch(
312+
client = Elasticsearch(
313313
"https://localhost:9200",
314314
bearer_auth="token-value"
315315
)
@@ -329,10 +329,10 @@ https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-cre
329329
from elasticsearch import Elasticsearch
330330
331331
# Adds the HTTP header 'Authorization: ApiKey <base64 api_key.id:api_key.api_key>'
332-
es = Elasticsearch(
332+
client = Elasticsearch(
333333
"https://localhost:9200",
334334
ca_certs="/path/to/http_ca.crt",
335-
api_key=("api_key.id", "api_key.api_key")
335+
api_key=("api_key")
336336
)
337337
----
338338

docs/sphinx/async.rst

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ and are used in the same way as other APIs, just with an extra ``await``:
2727
import asyncio
2828
from elasticsearch import AsyncElasticsearch
2929
30-
es = AsyncElasticsearch()
30+
client = AsyncElasticsearch()
3131
3232
async def main():
33-
resp = await es.search(
33+
resp = await client.search(
3434
index="documents",
3535
body={"query": {"match_all": {}}},
3636
size=20,
@@ -97,20 +97,20 @@ For example if using FastAPI that might look like this:
9797
from elasticsearch import AsyncElasticsearch
9898
9999
ELASTICSEARCH_URL = os.environ["ELASTICSEARCH_URL"]
100-
es = None
100+
client = None
101101
102102
@asynccontextmanager
103103
async def lifespan(app: FastAPI):
104-
global es
105-
es = AsyncElasticsearch(ELASTICSEARCH_URL)
104+
global client
105+
client = AsyncElasticsearch(ELASTICSEARCH_URL)
106106
yield
107-
await es.close()
107+
await client.close()
108108
109109
app = FastAPI(lifespan=lifespan)
110110
111111
@app.get("/")
112112
async def main():
113-
return await es.info()
113+
return await client.info()
114114
115115
You can run this example by saving it to ``main.py`` and executing
116116
``ELASTICSEARCH_URL=http://localhost:9200 uvicorn main:app``.
@@ -140,7 +140,7 @@ Bulk and Streaming Bulk
140140
from elasticsearch import AsyncElasticsearch
141141
from elasticsearch.helpers import async_bulk
142142
143-
es = AsyncElasticsearch()
143+
client = AsyncElasticsearch()
144144
145145
async def gendata():
146146
mywords = ['foo', 'bar', 'baz']
@@ -151,7 +151,7 @@ Bulk and Streaming Bulk
151151
}
152152
153153
async def main():
154-
await async_bulk(es, gendata())
154+
await async_bulk(client, gendata())
155155
156156
loop = asyncio.get_event_loop()
157157
loop.run_until_complete(main())
@@ -164,7 +164,7 @@ Bulk and Streaming Bulk
164164
from elasticsearch import AsyncElasticsearch
165165
from elasticsearch.helpers import async_streaming_bulk
166166
167-
es = AsyncElasticsearch()
167+
client = AsyncElasticsearch()
168168
169169
async def gendata():
170170
mywords = ['foo', 'bar', 'baz']
@@ -175,7 +175,7 @@ Bulk and Streaming Bulk
175175
}
176176
177177
async def main():
178-
async for ok, result in async_streaming_bulk(es, gendata()):
178+
async for ok, result in async_streaming_bulk(client, gendata()):
179179
action, result = result.popitem()
180180
if not ok:
181181
print("failed to %s document %s" % ())
@@ -194,11 +194,11 @@ Scan
194194
from elasticsearch import AsyncElasticsearch
195195
from elasticsearch.helpers import async_scan
196196
197-
es = AsyncElasticsearch()
197+
client = AsyncElasticsearch()
198198
199199
async def main():
200200
async for doc in async_scan(
201-
client=es,
201+
client=client,
202202
query={"query": {"match": {"title": "python"}}},
203203
index="orders-*"
204204
):

docs/sphinx/index.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,22 @@ Example Usage
5050
from datetime import datetime
5151
from elasticsearch import Elasticsearch
5252
53-
es = Elasticsearch("http://localhost:9200")
53+
client = Elasticsearch(cloud_id="YOUR_CLOUD_ID", api_key="YOUR_API_KEY")
5454
5555
doc = {
5656
"author": "kimchy",
5757
"text": "Elasticsearch: cool. bonsai cool.",
5858
"timestamp": datetime.now(),
5959
}
60-
resp = es.index(index="test-index", id=1, document=doc)
60+
resp = client.index(index="test-index", id=1, document=doc)
6161
print(resp["result"])
6262
63-
resp = es.get(index="test-index", id=1)
63+
resp = client.get(index="test-index", id=1)
6464
print(resp["_source"])
6565
66-
es.indices.refresh(index="test-index")
66+
client.indices.refresh(index="test-index")
6767
68-
resp = es.search(index="test-index", query={"match_all": {}})
68+
resp = client.search(index="test-index", query={"match_all": {}})
6969
print("Got {} hits:".format(resp["hits"]["total"]["value"]))
7070
for hit in resp["hits"]["hits"]:
7171
print("{timestamp} {author} {text}".format(**hit["_source"]))

0 commit comments

Comments
 (0)