| endpoint | get_source |
|---|---|
| lang | python |
| es_version | 9.3 |
| client | elasticsearch==9.3.0 |
Use client.get_source() to retrieve only the document body, without
metadata. This is a convenience over get() when you don't need
_version, _seq_no, or other metadata fields.
doc = client.get_source(index="products", id="prod-1")
print(f"{doc['name']} — ${doc['price']}")Use source_includes or source_excludes to return a subset of
fields:
doc = client.get_source(
index="products",
id="prod-1",
source_includes=["name", "price"],
)A NotFoundError is raised when the document does not exist:
from elasticsearch import NotFoundError
try:
doc = client.get_source(index="products", id="prod-999")
except NotFoundError:
print("Document not found")