Perform a search on several indices at the same time, with one method call.
Required ACL:searchThe returned results are broken down by query.
You can use up to 50 queries in a multiple queries request.
You can use this method for a search query or facet search by specifying the type parameter to be default or facet.This method can be useful in these scenarios:
You have multiple indices that serve different purposes.
This is typical when you want to search your main index
as well as an index that contains a history of searches.
You want to target one index and send it multiple queries,
where, for example, each query contains different settings or filters,
or the query itself is slightly adjusted.
Use the stopIfNotEnoughMatches strategy to stop the search early.
When using the method multiQueries, the request isn’t tied to any specific index.
As a result, when retrieving logs for a specific index, multiQueries logs won’t be retrieved.
// Perform three queries in a single API call:// First query targets index `categories`// Second and third queries target index `products`var indexQueries = new List<MultipleQueries>{ new MultipleQueries { IndexName = "categories", Params = new Query(myQueryString) { HitsPerPage = 3 } }, new MultipleQueries { IndexName = "products", Params = new Query(myQueryString) { HitsPerPage = 3, Filters = "_tags:promotion" } }, new MultipleQueries { IndexName = "products", Params = new Query(myQueryString) { HitsPerPage = 10 } },};MultipleQueriesRequest request = new MultipleQueriesRequest{ Requests = indexQueries};var res = client.MultipleQueries<object>(request);// Asynchronousvar res = await client.MultipleQueriesAsync<object>(request);
// Perform three queries in a single API call:// First query targets index `categories`// Second and third queries target index `products`var indexQueries = new List<MultipleQueries>{ new MultipleQueries { IndexName = "categories", Params = new Query(myQueryString) { HitsPerPage = 3 } }, new MultipleQueries { IndexName = "products", Params = new Query(myQueryString) { HitsPerPage = 3, Filters = "_tags:promotion" } }, new MultipleQueries { IndexName = "products", Params = new Query(myQueryString) { HitsPerPage = 10 } },};var requestOptions = new RequestOptions{ Headers = new Dictionary<string,string>{ { "X-Forwarded-For", "94.228.178.246" } }};MultipleQueriesRequest request = new MultipleQueriesRequest{ Requests = indexQueries};var res = client.MultipleQueries<object>(request, requestOptions);// Asynchronousvar res = await client.MultipleQueriesAsync<object>(request, requestOptions);
The strategy of the query.Can be one of the following values:
none: Execute the sequence of queries until the end.
This is recommended when each query is of equal importance, meaning all
records of all queries need to be returned.
stopIfEnoughMatches: Execute queries one by one, but stop as soon
as the cumulated number of hits is at least hitsPerPage.
This is recommended when each query is an alternative,
and where, if the first returns enough records,
there is no need to perform the remaining queries.
This section shows the JSON response returned by the API.
Each API client wraps this response in language-specific objects, so the structure may vary.
To view the response, use the getLogs method.
Don’t rely on the order of properties—JSON objects don’t preserve key order.