Skip to content

Latest commit

 

History

History
51 lines (41 loc) · 1023 Bytes

File metadata and controls

51 lines (41 loc) · 1023 Bytes
endpoint mget
lang python
es_version 9.3
client elasticsearch==9.3.0

Elasticsearch 9.3 mget endpoint (Python example)

Use client.mget() to retrieve multiple documents by ID in a single request. This is significantly faster than issuing individual get calls.

response = client.mget(
    index="products",
    ids=["prod-1", "prod-2", "prod-3"],
)

for doc in response["docs"]:
    if doc["found"]:
        print(f"{doc['_id']}: {doc['_source']['name']}")
    else:
        print(f"{doc['_id']}: not found")

Cross-index retrieval

Fetch documents from different indices in a single call by specifying _index per document:

response = client.mget(
    docs=[
        {"_index": "products", "_id": "prod-1"},
        {"_index": "orders", "_id": "order-42"},
    ]
)

Selecting fields

Use _source to limit which fields are returned:

response = client.mget(
    index="products",
    ids=["prod-1", "prod-2"],
    source_includes=["name", "price"],
)