Added client-level REST helpers. (#544)

* Added client-level REST helpers.

Signed-off-by: dblock <[email protected]>

* Move functions into an .http namespace.

Signed-off-by: dblock <[email protected]>

* Poetry update in samples.

Signed-off-by: dblock <[email protected]>

* Fix: typo.

Signed-off-by: dblock <[email protected]>

* Clarified what to use in which older versions.

Signed-off-by: dblock <[email protected]>

---------

Signed-off-by: dblock <[email protected]>
This commit is contained in:
Daniel (dB.) Doubrovkine
2023-11-13 12:52:13 -08:00
committed by GitHub
parent da436cbbe8
commit e68b9e762d
16 changed files with 1102 additions and 159 deletions
+7 -17
View File
@@ -31,7 +31,7 @@ async def main() -> None:
)
try:
info = await client.transport.perform_request("GET", "/")
info = await client.http.get("/")
print(
f"Welcome to {info['version']['distribution']} {info['version']['number']}!"
)
@@ -42,11 +42,7 @@ async def main() -> None:
index_body = {"settings": {"index": {"number_of_shards": 4}}}
print(
await client.transport.perform_request(
"PUT", f"/{index_name}", body=index_body
)
)
print(await client.http.put(f"/{index_name}", body=index_body))
# add a document to the index
@@ -55,8 +51,8 @@ async def main() -> None:
id = "1"
print(
await client.transport.perform_request(
"PUT", f"/{index_name}/_doc/{id}?refresh=true", body=document
await client.http.put(
f"/{index_name}/_doc/{id}?refresh=true", body=document
)
)
@@ -69,21 +65,15 @@ async def main() -> None:
"query": {"multi_match": {"query": q, "fields": ["title^2", "director"]}},
}
print(
await client.transport.perform_request(
"POST", f"/{index_name}/_search", body=query
)
)
print(await client.http.post(f"/{index_name}/_search", body=query))
# delete the document
print(
await client.transport.perform_request("DELETE", f"/{index_name}/_doc/{id}")
)
print(await client.http.delete(f"/{index_name}/_doc/{id}"))
# delete the index
print(await client.transport.perform_request("DELETE", f"/{index_name}"))
print(await client.http.delete(f"/{index_name}"))
finally:
await client.close()