A multidocument API handles a batch of documents in one request. For retrieval, Elasticsearch provides the _mget API: give it document IDs and it returns multiple documents, rather than fetching each one with a separate single-document request. Use it when an application already knows which records it needs, such as several movies selected from a catalog. section 5.2 section 5.2.2
For documents in one index, call the index-specific _mget endpoint and pass an ids array. This retrieves the requested IDs from movies in one operation. section 5.2.2
Listing 5.9 Fetching multiple documents at once
GET movies/_mget
{
"ids" : ["1", "12", "19", "34"]
}
The request places the known document IDs in ids. It is suited to several documents from the movies index. section 5.2.2
When requested documents belong to different indexes, use the cluster-level _mget endpoint. Its docs array contains one object per requested document, pairing _index with _id. This is useful when a result set spans separate collections, such as classic, international, and top-ranked movies. section 5.2.2
Listing 5.10 Fetching documents from three different indexes
GET _mget #1
{
"docs":[
{
"_index":"classic_movies", #2
"_id":11
},
{
"_index":"international_movies", #3
"_id":22
},
{
"_index":"top100_movies", #4
"_id":33
}
]
}
Each docs entry identifies exactly one target document: its index name and its ID. section 5.2.2
Plan for these response and request constraints:
- A missing document produces a JSON response indicating that it was not found. section 5.2
- A nonexistent index causes an index_not_found_exception. section 5.2.2
- For multi-index retrieval, provide an individual _index/_id pair for every requested document; _id does not accept an array of IDs in this form. section 5.2.2
_mget is one member of a broader set of multidocument APIs. Other batch-oriented operations include _bulk for indexing, deleting, or updating documents; query-based update and delete APIs; and _reindex for moving data between indexes. Choose _mget specifically when the task is to retrieve known IDs, not to search for matching documents. section 3.2.1 section 5.0 section 5.8
