| endpoint | get |
|---|---|
| lang | python |
| es_version | 9.3 |
| client | elasticsearch==9.3.0 |
Use client.get() to retrieve a document by its ID.
response = client.get(index="products", id="prod-1")
doc = response["_source"]
print(f"{doc['name']} — ${doc['price']}")The response includes metadata (_index, _id, _version,
_seq_no, _primary_term) alongside the _source document body.
Use source_includes or source_excludes to return only the fields
you need:
response = client.get(
index="products",
id="prod-1",
source_includes=["name", "price"],
)To fetch metadata without the source body, disable it entirely:
response = client.get(index="products", id="prod-1", source=False)
version = response["_version"]A NotFoundError is raised when the document does not exist:
from elasticsearch import NotFoundError
try:
response = client.get(index="products", id="prod-999")
except NotFoundError:
print("Document not found")