[[reference-msearch]]
== client.msearch

////////
===========================================================================================================================
||                                                                                                                       ||
||                                                                                                                       ||
||                                                                                                                       ||
||        ██████╗ ███████╗ █████╗ ██████╗ ███╗   ███╗███████╗                                                            ||
||        ██╔══██╗██╔════╝██╔══██╗██╔══██╗████╗ ████║██╔════╝                                                            ||
||        ██████╔╝█████╗  ███████║██║  ██║██╔████╔██║█████╗                                                              ||
||        ██╔══██╗██╔══╝  ██╔══██║██║  ██║██║╚██╔╝██║██╔══╝                                                              ||
||        ██║  ██║███████╗██║  ██║██████╔╝██║ ╚═╝ ██║███████╗                                                            ||
||        ╚═╝  ╚═╝╚══════╝╚═╝  ╚═╝╚═════╝ ╚═╝     ╚═╝╚══════╝                                                            ||
||                                                                                                                       ||
||                                                                                                                       ||
||    This file is autogenerated, DO NOT send pull requests that changes this file directly.                             ||
||    You should update the script that does the generation, which can be found in:                                      ||
||    https://github.com/elastic/elastic-client-generator-js                                                             ||
||                                                                                                                       ||
||    You can run the script with the following command:                                                                 ||
||       npm run elasticsearch -- --version <version>                                                                    ||
||                                                                                                                       ||
||                                                                                                                       ||
||                                                                                                                       ||
===========================================================================================================================
////////
++++
<style>
.lang-ts a.xref {
  text-decoration: underline !important;
}
</style>
++++


[discrete]
[[client.msearch]]
== `client.msearch()`

Run multiple searches. The format of the request is similar to the bulk API format and makes use of the newline delimited JSON (NDJSON) format. The structure is as follows: ``` header\n body\n header\n body\n ``` This structure is specifically optimized to reduce parsing if a specific search ends up redirected to another node. IMPORTANT: The final line of data must end with a newline character `\n`. Each newline character may be preceded by a carriage return `\r`. When sending requests to this endpoint the `Content-Type` header should be set to `application/x-ndjson`.

{ref}/search-multi-search.html[{es} documentation]
[discrete]
=== Function signature

[source,ts]
----
(request: MsearchRequest, options?: TransportRequestOptions) => Promise<MsearchResponse>
----

[discrete]
=== Request

[source,ts,subs=+macros]
----
interface MsearchRequest extends <<RequestBase>> {
  index?: <<Indices>>
  allow_no_indices?: boolean
  ccs_minimize_roundtrips?: boolean
  expand_wildcards?: <<ExpandWildcards>>
  ignore_throttled?: boolean
  ignore_unavailable?: boolean
  include_named_queries_score?: boolean
  max_concurrent_searches?: <<long>>
  max_concurrent_shard_requests?: <<long>>
  pre_filter_shard_size?: <<long>>
  rest_total_hits_as_int?: boolean
  routing?: <<Routing>>
  search_type?: <<SearchType>>
  typed_keys?: boolean
  searches?: <<MsearchRequestItem>>[]
}

----


[discrete]
=== Response

[source,ts,subs=+macros]
----
type MsearchResponse<TDocument = unknown, TAggregations = Record<<<AggregateName>>, <<AggregationsAggregate>>>> = <<MsearchMultiSearchResult>><TDocument, TAggregations>

----


