Method: Elasticsearch::API::Actions#mget

Defined in:
lib/elasticsearch/api/actions/mget.rb

#mget(arguments = {}) ⇒ Object

Get multiple documents. 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.

Parameters:

  • (defaults to: {})

    a customizable set of options

Options Hash (arguments):

  • :index (String)

    Name of the index to retrieve documents from when ids are specified, or when a document in the docs array does not specify an index.

  • :force_synthetic_source (Boolean)

    Should this request force synthetic _source? Use this to test if the mapping supports synthetic _source and to get a sense of the worst case performance. Fetches with this enabled will be slower the enabling synthetic source natively in the index.

  • :preference (String)

    Specifies the node or shard the operation should be performed on. Random by default.

  • :realtime (Boolean)

    If true, the request is real-time as opposed to near-real-time. Server default: true.

  • :refresh (Boolean)

    If true, the request refreshes relevant shards before retrieving documents.

  • :routing (String)

    Custom value used to route operations to a specific shard.

  • :_source (Boolean, String, Array<String>)

    True or false to return the _source field or not, or a list of fields to return.

  • :_source_excludes (String, Array<String>)

    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_includes query parameter.

  • :_source_includes (String, Array<String>)

    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_excludes query parameter. If the _source parameter is false, this parameter is ignored.

  • :stored_fields (String, Array<String>)

    If true, retrieves the document fields stored in the index rather than the document _source. Server default: false.

  • :error_trace (Boolean)

    When set to true Elasticsearch will include the full stack trace of errors when they occur.

  • :filter_path (String, Array<String>)

    Comma-separated list of filters in dot notation which reduce the response returned by Elasticsearch.

  • :human (Boolean)

    When set to true will return statistics in a format suitable for humans. For example ‘“exists_time”: “1h”` for humans and `“exists_time_in_millis”: 3600000` for computers. When disabled the human readable values will be omitted. This makes sense for responses being consumed only by machines.

  • :pretty (Boolean)

    If set to true the returned JSON will be “pretty-formatted”. Only use this option for debugging only.

  • :headers (Hash)

    Custom HTTP headers

  • :body (Hash)

    request body

Raises:

See Also:



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/elasticsearch/api/actions/mget.rb', line 68

def mget(arguments = {})
  request_opts = { endpoint: arguments[:endpoint] || 'mget' }

  defined_params = [:index].each_with_object({}) do |variable, set_variables|
    set_variables[variable] = arguments[variable] if arguments.key?(variable)
  end
  request_opts[:defined_params] = defined_params unless defined_params.empty?

  raise ArgumentError, "Required argument 'body' missing" unless arguments[:body]

  arguments = arguments.clone
  headers = arguments.delete(:headers) || {}

  body = arguments.delete(:body)

  _index = arguments.delete(:index)

  method = Elasticsearch::API::HTTP_POST
  path   = if _index
             "#{Utils.listify(_index)}/_mget"
           else
             '_mget'
           end
  params = Utils.process_params(arguments)

  Elasticsearch::API::Response.new(
    perform_request(method, path, params, body, headers, request_opts)
  )
end