Get multiple documents
- POST also GET /{index}/_mget
- POST also GET /_mget
Get multiple JSON documents by ID from one or more indices. If you specify an index in the request URI, you only need to specify the document IDs in the request body. To ensure fast responses, this multi get (mget) API responds with partial results if one or more shards fail.
Filter source fields
By default, the _source field is returned for every document (if stored).
Use the _source and _source_include or source_exclude attributes to filter what fields are returned for a particular document.
You can include the _source, _source_includes, and _source_excludes query parameters in the request URI to specify the defaults to use when there are no per-document instructions.
Get stored fields
Use the stored_fields attribute to specify the set of stored fields you want to retrieve.
Any requested fields that are not stored are ignored.
You can include the stored_fields query parameter in the request URI to specify the defaults to use when there are no per-document instructions.
Required authorization
- Index privileges read
Query parameters
-
preferencestring -
Specifies the node or shard the operation should be performed on. Random by default.
-
refreshboolean · default: false -
If
true, the request refreshes relevant shards before retrieving documents. -
routingoneOf -
Custom value used to route operations to a specific shard. Not allowed when
index.slice.enabledistruefor the target index; use_sliceinstead. -
_source_excludesoneOf -
A comma-separated list of source fields to exclude from the response. You can also use this parameter to exclude fields from the subset specified in
_source_includesquery parameter. -
_source_includesoneOf -
A comma-separated list of source fields to include in the response. If this parameter is specified, only these source fields are returned. You can exclude fields from this subset using the
_source_excludesquery parameter. If the_sourceparameter isfalse, this parameter is ignored.
Request body
-
docsobject -
The documents you want to retrieve. Required if no index is specified in the request URI.
-
routingstring -
The key for the primary shard the document resides on. Required if routing is used during indexing.
-
version_type -
Supported values include:
internal: Use internal versioning that starts at 1 and increments with each update or delete.external: Only index the document if the specified version is strictly higher than the version of the stored document or if there is no existing document.external_gte: Only index the document if the specified version is equal or higher than the version of the stored document or if there is no existing document. NOTE: Theexternal_gteversion type is meant for special use cases and should be used with care. If used incorrectly, it can result in loss of data.
-
Values:
internalexternalexternal_gte
Response
-
docsoneOfrequired -
The response includes a docs array that contains the documents in the order specified in the request. The structure of the returned documents is similar to that returned by the get API. If there is a failure getting a particular document, the error is included in place of the document.