mget

edit
client.mget([params, [callback]])

Get multiple documents based on an index, type (optional) and ids. The body required by mget can take two forms: an array of document locations, or an array of document ids.

Check the API Conventions and the elasticsearch docs for more information pertaining to this method.

An array of doc locations. Useful for getting documents from different indices.

const response = await client.mget({
  body: {
    docs: [
      { _index: 'indexA', _type: 'typeA', _id: '1' },
      { _index: 'indexB', _type: 'typeB', _id: '1' },
      { _index: 'indexC', _type: 'typeC', _id: '1' }
    ]
  }
});

An array of ids. You must also specify the index and type that apply to all of the ids.

const response = await client.mget({
  index: 'myindex',
  type: 'mytype',
  body: {
    ids: [1, 2, 3]
  }
});

Params

storedFields

String, String[], Boolean — A comma-separated list of stored fields to return in the response

preference

String — Specify the node or shard the operation should be performed on (default: random)

realtime

Boolean — Specify whether to perform the operation in realtime or search mode

refresh

Boolean — Refresh the shard containing the document before performing the operation

routing

String — Specific routing value

_source

String, String[], Boolean — True or false to return the _source field or not, or a list of fields to return

_sourceExclude

String, String[], Boolean — A list of fields to exclude from the returned _source field

_sourceInclude

String, String[], Boolean — A list of fields to extract and return from the _source field

index

String — The name of the index

type

String — The type of the document

body

Object, JSON — The request body, as either JSON or a JSON serializable object. See the elasticsearch docs for details about what can be specified here.

back to top