[[distrib-multi-doc]] === Multidocument Patterns
The patterns for the mget
and bulk
APIs((("mget (multi-get) API", "retrieving multiple documents, process of")))((("documents", "retrieving multiple with mget"))) are similar to those for
individual documents. The difference is that the requesting node knows in
which shard each document lives. It breaks up the multidocument request into
a multidocument request per shard, and forwards these in parallel to each
participating node.
Once it receives answers from each node, it collates their responses
into a single response, which it returns to the client, as shown in <
[[img-distrib-mget]]
.Retrieving multiple documents with mget
image::images/elas_0405.png["Retrieving multiple documents with mget"]
Here is the sequence of steps necessary to retrieve multiple documents
with a single mget
request:
The client sends an mget
request to Node 1
.
Node 1
builds a multi-get request per shard, and forwards these
requests in parallel to the nodes hosting each required primary or replica
shard. Once all replies have been received, Node 1
builds the response
and returns it to the client.
A routing
parameter can ((("routing parameter")))be set for each document in the docs
array.
The bulk API, as depicted in <
[[img-distrib-bulk]]
.Multiple document changes with bulk
image::images/elas_0406.png["Multiple document changes with bulk"]
The sequence of steps((("bulk API", "multiple document changes with")))((("documents", "multiple changes with bulk"))) followed by the
bulk
API are as follows:
The client sends a bulk
request to Node 1
.
Node 1
builds a bulk request per shard, and forwards these requests in
parallel to the nodes hosting each involved primary shard.
The primary shard executes each action serially, one after another. As each action succeeds, the primary forwards the new document (or deletion) to its replica shards in parallel, and then moves on to the next action. Once all replica shards report success for all actions, the node reports success to the requesting node, which collates the responses and returns them to the client.
The bulk
API also accepts((("replication request parameter", "in bulk requests")))((("consistency request parameter", "in bulk requests"))) the replication
and consistency
parameters
at the top level for the whole bulk
request, and the routing
parameter
in the metadata for each request.