This is documentation for v3 of the PHP API clients, which is not the latest version.
To see the documentation for the latest version, see
PHP v4.
This is documentation for v2 of the Ruby API clients, which is not the latest version.
To see the documentation for the latest version, see
Ruby v3.
This is documentation for v4 of the JavaScript API clients, which is not the latest version.
To see the documentation for the latest version, see
JavaScript v5.
This is documentation for v3 of the Python API clients, which is not the latest version.
To see the documentation for the latest version, see
Python v4.
This is documentation for v8 of the Swift API clients, which is not the latest version.
To see the documentation for the latest version, see
Swift v9.
This is documentation for v2 of the Kotlin API clients, which is not the latest version.
To see the documentation for the latest version, see
Kotlin v3.
This is documentation for v6 of the C# API clients, which is not the latest version.
To see the documentation for the latest version, see
C# v7.
This is documentation for v3 of the Java API clients, which is not the latest version.
To see the documentation for the latest version, see
Java v4.
This is documentation for v3 of the Go API clients, which is not the latest version.
To see the documentation for the latest version, see
Go v4.
This is documentation for v1 of the Scala API clients, which is not the latest version.
To see the documentation for the latest version, see
Scala v2.
$client->multipleQueries(arrayqueries)
$client->multipleQueries(arrayqueries, [
// All the following parameters are optional
'strategy' => string,
// + any requestOptions
])
client.multipleQueries(arrayqueries)
client.multipleQueries(arrayqueries, {
// All the following parameters are optionalstrategy: string,
// + any requestOptions
})
client.multiple_queries(dictqueries)
client.multiple_queries(dictqueries, {
# All the following parameters are optional
'strategy' => string,
# + any requestOptions
})
client.MultipleQueries(new MultipleQueriesRequest
{
Queries = IEnumerable<MultipleQueries>,
Strategy = String
},
// All the following parameters are optionalRequestOptions: RequestOptions
)
client.multipleQueries(
new MultipleQueriesRequest( List<MultipleQueries>queries),
Contact.class
)
client.multipleQueries(
new MultipleQueriesRequest( List<MultipleQueries>queries, MultiQueriesStrategystrategy),
Contact.class
)
client.multipleQueries(
new MultipleQueriesRequest( List<MultipleQueries>queries),
Contact.class
RequestOptionsrequestOptions
)
client.multipleQueries(
new MultipleQueriesRequest( List<MultipleQueries>queries, MultiQueriesStrategystrategy),
Contact.class
RequestOptionsrequestOptions
)
You’re currently reading the JavaScript API client v4 documentation.
Check the migration guide to learn how to upgrade from v3 to v4. You can still access the v3 documentation.
Perform a search on several indices at the same time, with one method call.
The returned results are broken down by query.
This method can be used in several different kinds of situations.
Here are two typical usage 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 (to be used for autocomplete).
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.
Note that for 2., you will want to use the “stopIfEnoughMatches”
value of the strategy parameter.
You can use this method for a search query or facet search by specifying the type parameter to be “default” or “facet”.
You can only use up to 50 queries in a multiple queries request.
When using the method multiQueries, the request will not be 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`$queries=[['indexName'=>'categories','query'=>$myQueryString,'hitsPerPage'=>3],['indexName'=>'products','query'=>$myQueryString,'hitsPerPage'=>3,'facetFilters'=>'promotion'],['indexName'=>'products','query'=>$myQueryString,'hitsPerPage'=>10]];$results=$client->multipleQueries($queries);var_dump($results['results']);
1
2
3
4
5
6
7
8
9
10
# Perform three queries in a single API call:# First query targets index `categories`# Second and third queries target index `products`res=client.multiple_queries([{indexName: 'categories',query: my_query_string,hitsPerPage: 3},{indexName: 'products',query: my_query_string,filters: '_tags:promotion'},{indexName: 'products',query: my_query_string,hitsPerPage: 10}])putsres['results']
constqueries=[{indexName:'categories',query:'search in categories index',params:{hitsPerPage:3}},{indexName:'products',query:'first search in products',params:{hitsPerPage:3,filters:'_tags:promotion'}},{indexName:'products',query:'another search in products',params:{hitsPerPage:10}}];// Perform three queries in a single API call:// First query targets index `categories`// Second and third queries target index `products`client.multipleQueries(queries).then(({results})=>{console.log(results);});
1
2
3
4
5
6
7
8
9
10
# Perform three queries in a single API call:
# First query targets index `categories`
# Second and third queries target index `products`
results=client.multiple_queries([{'indexName':'categories','query':myQueryString,'hitsPerPage':3},{'indexName':'products','query':myQueryString,'filters':'_tags:promotion'},{'indexName':'products','query':myQueryString,'hitsPerPage':3},])print(results['results'])
1
2
3
4
5
6
7
8
9
10
11
12
13
14
// Perform three queries in a single API call:// First query target index `categories`// Second and third queries target index `products`letqueries:[IndexedQuery]=[.init(indexName:"categories",query:Query("electronics").set(\.hitsPerPage,to:3)),.init(indexName:"products",query:Query("iPhone").set(\.hitsPerPage,to:3).set(\.filters,to:"_tags:promotions")),.init(indexName:"products",query:Query("Galaxy").set(\.hitsPerPage,to:10)),]client.multipleQueries(queries:queries){resultinifcase.success(letresponse)=result{print("Response: \(response)")}}
// Perform three queries in a single API call:// First query targets index `categories`// Second and third queries target index `products`varindexQueries=newList<MultipleQueries>{newMultipleQueries{IndexName="categories",Params=newQuery(myQueryString){HitsPerPage=3}},newMultipleQueries{IndexName="products",Params=newQuery(myQueryString){HitsPerPage=3,Filters="_tags:promotion"}},newMultipleQueries{IndexName="products",Params=newQuery(myQueryString){HitsPerPage=10}},};MultipleQueriesRequestrequest=newMultipleQueriesRequest{Requests=indexQueries};varres=client.MultipleQueries<object>(request);// Asynchronousvarres=awaitclient.MultipleQueriesAsync<object>(request);
//Sync version// Perform three queries in a single API call:// First query targets index `categories`// Second and third queries target index `products`List<MultipleQueries>queries=Arrays.asList(newMultipleQueries("categories",newQuery(myQueryString).setHitsPerPage(3)),newMultipleQueries("products",newQuery(myQueryString).setHitsPerPage(3).setFilters("_tags:promotion")),newMultipleQueries("products",newQuery(myQueryString).setHitsPerPage(10)));MultipleQueriesResponse<Object>search=client.multipleQueries(newMultipleQueriesRequest(queries),Contact.class);//Async versionCompletableFuture<MultipleQueriesResponse<Object>>search=client.multipleQueriesAsync(queries,Contact.class);
1
2
3
4
5
6
7
8
9
// Perform three queries in a single API call:// First query targets the `categories` index// Second and third queries target the `products` indexqueries:=[]search.IndexedQuery{search.NewIndexedQuery("categories",opt.Query("computer"),opt.HitsPerPage(3)),search.NewIndexedQuery("products",opt.Query("computer"),opt.HitsPerPage(3),opt.Filters("_tags:promotion")),search.NewIndexedQuery("products",opt.Query("computer"),opt.HitsPerPage(10)),}res,err:=client.MultipleQueries(queries,"")
// Perform three queries in a single API call:// First query targets index `categories`// Second and third queries target index `products`client.execute{multiQueries(searchinto"categories"queryQuery(query=myQueryString,hitsPerPage=Some(3)),searchinto"products"queryQuery(query=myQueryString,hitsPerPage=Some(3),filters=Some("_tags:promotion")),searchinto"products"queryQuery(query=myQueryString,hitsPerPage=Some(10)))strategyMultiQueries.Strategy.stopIfEnoughMatches}
# Perform three queries in a single API call:
# First query targets index `categories`
# Second and third queries target index `products`
results=client.multiple_queries([{'indexName':'categories','query':my_query_string,'hitsPerPage':3},{'indexName':'products','query':my_query_string,'filters':'_tags:promotion'},{'indexName':'products','query':my_query_string,'hitsPerPage':10}],{'X-Forwarded-For':'94.228.178.246'})print(results['results'])
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// Perform three queries in a single API call:// First query target index `categories`// Second and third queries target index `products`letqueries:[IndexedQuery]=[.init(indexName:"categories",query:Query("electronics").set(\.hitsPerPage,to:3)),.init(indexName:"products",query:Query("iPhone").set(\.hitsPerPage,to:3).set(\.filters,to:"_tags:promotions")),.init(indexName:"products",query:Query("Galaxy").set(\.hitsPerPage,to:10)),]varrequestOptions=RequestOptions()requestOptions.headers["X-Forwarded-For"]="94.228.178.246"client.multipleQueries(queries:queries,requestOptions:requestOptions){resultinifcase.success(letresponse)=result{print("Response: \(response)")}}
// Perform three queries in a single API call:// First query targets index `categories`// Second and third queries target index `products`varindexQueries=newList<MultipleQueries>{newMultipleQueries{IndexName="categories",Params=newQuery(myQueryString){HitsPerPage=3}},newMultipleQueries{IndexName="products",Params=newQuery(myQueryString){HitsPerPage=3,Filters="_tags:promotion"}},newMultipleQueries{IndexName="products",Params=newQuery(myQueryString){HitsPerPage=10}},};varrequestOptions=newRequestOptions{Headers=newDictionary<string,string>{{"X-Forwarded-For","94.228.178.246"}}};MultipleQueriesRequestrequest=newMultipleQueriesRequest{Requests=indexQueries};varres=client.MultipleQueries<object>(request,requestOptions);// Asynchronousvarres=awaitclient.MultipleQueriesAsync<object>(request,requestOptions);
//Sync version// Perform three queries in a single API call:// First query targets index `categories`// Second and third queries target index `products`List<IndexQuery>queries=Arrays.asList(newIndexQuery("categories",newQuery(myQueryString).setHitsPerPage(3)),newIndexQuery("products",newQuery(myQueryString).setHitsPerPage(3).setFilters("_tags:promotion")),newIndexQuery("products",newQuery(myQueryString).setHitsPerPage(10)));MultiQueriesResultsearch=client.multipleQueries(queries,Contact.class,newRequestOptions().addExtraHeader("X-Forwarded-For","94.228.178.246"));//Async version// Perform three queries in a single API call:// First query targets index `categories`// Second and third queries target index `products`List<IndexQuery>queries=Arrays.asList(newIndexQuery("categories",newQuery(myQueryString).setHitsPerPage(3)),newIndexQuery("products",newQuery(myQueryString).setHitsPerPage(3).setFilters("_tags:promotion")),newIndexQuery("products",newQuery(myQueryString).setHitsPerPage(10)));CompletableFuture<MultiQueriesResult>search=client.multipleQueries(queries,Contact.class,newRequestOptions().addExtraHeader("X-Forwarded-For","94.228.178.246"));
1
2
3
4
5
6
7
8
9
10
11
12
13
// Perform three queries in a single API call:// First query targets the `categories` index// Second and third queries target the `products` indexqueries:=[]search.IndexedQuery{search.NewIndexedQuery("categories",opt.Query("computer"),opt.HitsPerPage(3)),search.NewIndexedQuery("products",opt.Query("computer"),opt.HitsPerPage(3),opt.Filters("_tags:promotion")),search.NewIndexedQuery("products",opt.Query("computer"),opt.HitsPerPage(10)),}extraHeaders:=opt.ExtraHeaders(map[string]string{"X-Forwarded-For":"94.228.178.246",})res,err:=client.MultipleQueries(queries,"",extraHeaders)
// Perform three queries in a single API call:// First query targets index `categories`// Second and third queries target index `products`client.execute{multiQueries(searchinto"categories"queryQuery(query=myQueryString,hitsPerPage=Some(3)),searchinto"products"queryQuery(query=myQueryString,hitsPerPage=Some(3),filters=Some("_tags:promotion")),searchinto"products"queryQuery(query=myQueryString,hitsPerPage=Some(10)))strategyMultiQueries.Strategy.stopIfEnoughMatchesoptionsRequestOptions(extraHeaders=Some(Map("X-Forwarded-For"=>"94.228.178.246")))}
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 encapsulates this response inside objects specific to the programming language,
so that the actual response might be different.
You can view the response by using the getLogs method.
Don’t rely on the order of attributes in the response, as JSON doesn’t guarantee the ordering of keys in objects.