liveBook · Manning

Multidocument API

As explained in Elasticsearch in Action, Second Edition

An Elasticsearch API that retrieves multiple documents by their indexes and document IDs in one request.

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

How Elasticsearch in Action, Second Edition covers it

How deep it goes
Explains same-index and cross-index request formats, plus missing-document and missing-index behavior; it does not describe response fields.
Examples
Uses movies IDs in one index and three movie documents drawn from classic_movies, international_movies, and top100_movies.
What it assumes
Introduces retrieval through document IDs and index names without requiring prior schema design knowledge.
What you can do after
Apply it via the _mget API to fetch known IDs from one index or explicit index/ID pairs across indexes.
How it connects
Connects _mget to single-document APIs, _bulk, update by query, delete by query, reindexing, indexes, and document IDs.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Elasticsearch in Action, Second Edition. The section links point to the parts of the book it draws on.