Skip to content

Commit 9db01a3

Browse files
committed
more replacing es with client
1 parent 969b77f commit 9db01a3

File tree

4 files changed

+25
-25
lines changed

4 files changed

+25
-25
lines changed

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

examples/fastapi-apm/app.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515
apm = make_apm_client(
1616
{"SERVICE_NAME": "fastapi-app", "SERVER_URL": "http://apm-server:8200"}
1717
)
18-
es = AsyncElasticsearch(os.environ["ELASTICSEARCH_HOSTS"])
18+
client = AsyncElasticsearch(os.environ["ELASTICSEARCH_HOSTS"])
1919
app = FastAPI()
2020
app.add_middleware(ElasticAPM, client=apm)
2121

2222

2323
@app.on_event("shutdown")
2424
async def app_shutdown():
25-
await es.close()
25+
await client.close()
2626

2727

2828
async def download_games_db():
@@ -35,16 +35,16 @@ async def download_games_db():
3535

3636
@app.get("/")
3737
async def index():
38-
return await es.cluster.health()
38+
return await client.cluster.health()
3939

4040

4141
@app.get("/ingest")
4242
async def ingest():
43-
if not (await es.indices.exists(index="games")):
44-
await es.indices.create(index="games")
43+
if not (await client.indices.exists(index="games")):
44+
await client.indices.create(index="games")
4545

4646
async for _ in async_streaming_bulk(
47-
client=es, index="games", actions=download_games_db()
47+
client=client, index="games", actions=download_games_db()
4848
):
4949
pass
5050

@@ -53,34 +53,34 @@ async def ingest():
5353

5454
@app.get("/search/{query}")
5555
async def search(query):
56-
return await es.search(
56+
return await client.search(
5757
index="games", body={"query": {"multi_match": {"query": query}}}
5858
)
5959

6060

6161
@app.get("/delete")
6262
async def delete():
63-
return await es.delete_by_query(index="games", body={"query": {"match_all": {}}})
63+
return await client.delete_by_query(index="games", body={"query": {"match_all": {}}})
6464

6565

6666
@app.get("/delete/{id}")
6767
async def delete_id(id):
6868
try:
69-
return await es.delete(index="games", id=id)
69+
return await client.delete(index="games", id=id)
7070
except NotFoundError as e:
7171
return e.info, 404
7272

7373

7474
@app.get("/update")
7575
async def update():
7676
response = []
77-
docs = await es.search(
77+
docs = await client.search(
7878
index="games", body={"query": {"multi_match": {"query": ""}}}
7979
)
8080
now = datetime.datetime.utcnow()
8181
for doc in docs["hits"]["hits"]:
8282
response.append(
83-
await es.update(
83+
await client.update(
8484
index="games", id=doc["_id"], body={"doc": {"modified": now}}
8585
)
8686
)
@@ -91,11 +91,11 @@ async def update():
9191
@app.get("/error")
9292
async def error():
9393
try:
94-
await es.delete(index="games", id="somerandomid")
94+
await client.delete(index="games", id="somerandomid")
9595
except NotFoundError as e:
9696
return e.info
9797

9898

9999
@app.get("/doc/{id}")
100100
async def get_doc(id):
101-
return await es.get(index="games", id=id)
101+
return await client.get(index="games", id=id)

0 commit comments

Comments
 (0)