Skip to content

Latest commit

 

History

History
43 lines (33 loc) · 931 Bytes

File metadata and controls

43 lines (33 loc) · 931 Bytes
endpoint get_source
lang python
es_version 9.3
client elasticsearch==9.3.0

Elasticsearch 9.3 get_source endpoint (Python example)

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']}")

Selecting fields

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"],
)

Handling missing documents

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")