Skip to main content
This page documents an earlier version of the API client. For the latest version, see Search multiple indices.
Required ACL: search The 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:
  1. 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.
  2. 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.

Examples

Multiple queries

// 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);

// Asynchronous
var res = await client.MultipleQueriesAsync<object>(request);

Multiple queries and send extra HTTP headers

// 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);

// Asynchronous
var res = await client.MultipleQueriesAsync<object>(request, requestOptions);

Parameters

queries
object[]
required
A list of queries to execute.
requestOptions
object
A mapping of request options to send along with the query.
strategy
string
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.

Response

results
object[]
List of # in the order they were submitted, one element for each query.Example:
JSON
{
  "results": [
    {
      [...],
      index: 'indexName'
      processed: true
    },
    [...]
  ]
}

Response as JSON

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.
JSON
{
  "results": [
    {
      "hits": [
        {
          "firstname": "Jimmie",
          "lastname": "Barninger",
          "objectID": "433",
          "_highlightResult": {
            "firstname": {
              "value": "<em>Jimmie</em>",
              "matchLevel": "partial"
            },
            "lastname": {
              "value": "Barninger",
              "matchLevel": "none"
            },
            "company": {
              "value": "California <em>Paint</em> & Wlpaper Str",
              "matchLevel": "partial"
            }
          }
        }
        ],
        "page": 0,
        "nbHits": 1,
        "nbPages": 1,
        "hitsPerPage": 20,
        "processingTimeMS": 1,
        "query": "jimmie paint",
        "params": "query=jimmie+paint&attributesToRetrieve=firstname,lastname&hitsPerPage=50"
        "index": "people"
    },
    {
      "hits": [
        {
          "firstname": "Jimmie",
          "lastname": "Barninger",
          "objectID": "433",
          "_highlightResult": {
            "firstname": {
              "value": "<em>Jimmie</em>",
              "matchLevel": "partial"
            },
            "lastname": {
              "value": "Barninger",
              "matchLevel": "none"
            },
            "company": {
              "value": "California <em>Paint</em> & Wlpaper Str",
              "matchLevel": "partial"
            }
          }
        }
        ],
        "page": 0,
        "nbHits": 1,
        "nbPages": 1,
        "hitsPerPage": 20,
        "processingTimeMS": 1,
        "query": "jimmie paint",
        "params": "query=jimmie+paint&attributesToRetrieve=firstname,lastname&hitsPerPage=50"
        "index": "famous_people"
    }
  ]
}
I