Method: OpenSearch::API::Actions#msearch

Defined in:
lib/opensearch/api/actions/msearch.rb

#msearch(arguments = {}) ⇒ Object

Allows to execute several search operations in one request.

*Deprecation notice*: Specifying types in urls has been deprecated Deprecated since version 7.0.0

Parameters:

  • arguments (Hash) (defaults to: {})

    a customizable set of options

Options Hash (arguments):

  • :index (List)

    A comma-separated list of index names to use as default

  • :search_type (String)

    Search operation type (options: query_then_fetch, dfs_query_then_fetch)

  • :max_concurrent_searches (Number)

    Controls the maximum number of concurrent searches the multi search api will execute

  • :typed_keys (Boolean)

    Specify whether aggregation and suggester names should be prefixed by their respective types in the response

  • :pre_filter_shard_size (Number)

    A threshold that enforces a pre-filter roundtrip to prefilter search shards based on query rewriting if the number of shards the search request expands to exceeds the threshold. This filter roundtrip can limit the number of shards significantly if for instance a shard can not match any documents based on its rewrite method ie. if date filters are mandatory to match but the shard bounds and the query are disjoint.

  • :max_concurrent_shard_requests (Number)

    The number of concurrent shard requests each sub search executes concurrently per node. This value should be used to limit the impact of the search on the cluster in order to limit the number of concurrent shard requests

  • :rest_total_hits_as_int (Boolean)

    Indicates whether hits.total should be rendered as an integer or an object in the rest search response

  • :ccs_minimize_roundtrips (Boolean)

    Indicates whether network round-trips should be minimized as part of cross-cluster search requests execution

  • :headers (Hash)

    Custom HTTP headers

  • :body (Hash)

    The request definitions (metadata-search request definition pairs), separated by newlines (Required)

Raises:

  • (ArgumentError)


49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/opensearch/api/actions/msearch.rb', line 49

def msearch(arguments = {})
  raise ArgumentError, "Required argument 'body' missing" unless arguments[:body]

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

  arguments = arguments.clone

  _index = arguments.delete(:index)

  method = OpenSearch::API::HTTP_POST
  path   = if _index
             "#{Utils.__listify(_index)}/_msearch"
           else
             "_msearch"
           end
  params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)

  body = arguments[:body]
  case
  when body.is_a?(Array) && body.any? { |d| d.has_key? :search }
    payload = body
              .inject([]) do |sum, item|
                meta = item
                data = meta.delete(:search)

                sum << meta
                sum << data
                sum
              end
              .map { |item| OpenSearch::API.serializer.dump(item) }
    payload << "" unless payload.empty?
    payload = payload.join("\n")
  when body.is_a?(Array)
    payload = body.map { |d| d.is_a?(String) ? d : OpenSearch::API.serializer.dump(d) }
    payload << "" unless payload.empty?
    payload = payload.join("\n")
  else
    payload = body
  end

  headers.merge!("Content-Type" => "application/x-ndjson")
  perform_request(method, path, params, payload, headers).body
end