Skip to content

Does MultiSearchRequest request returns response in the same sequence as it was added in SearchRequest?

I am using MultiSearchRequest to execute multiple search queries using SearchRequest as below:

MultiSearchRequest request = new MultiSearchRequest();

SearchRequest searchRequest = new SearchRequest(IndexName.MYINDEX.getValue());
request.add(searchRequest);//Mutliple search queries are added here in a loop.

My question is when i call:

MultiSearchResponse response = client.msearch(request, RequestOptions.DEFAULT);

can i expect to get response in the same sequence as the requests were added OR they will be at random. Currently i am assuming it will be returning response in sequence as they were added but in PARALLEL.



Multi Search API in short YES

Response body

(array) Includes the search response and status code for each search request matching its order in the original multi search request. If there was a complete failure for a specific search request, an object with error message and corresponding status code will be returned in place of the actual search response.