Skip to main content
Required ACL: search Use cases include:
  • Searching different indices, such as products and marketing content.
  • Run multiple queries on the same index with different parameters or filters.
If you know the expected result type, use the searchForHits or searchForFacets helper to simplify the response format.

Usage

// Initialize the client
var client = new SearchClient(new SearchConfig("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY"));

// Call the API
var response = await client.SearchAsync<Hit>(
  new SearchMethodParams
  {
    Requests = new List<SearchQuery>
    {
      new SearchQuery(new SearchForHits { IndexName = "<YOUR_INDEX_NAME>" }),
      new SearchQuery(
        new SearchForFacets
        {
          IndexName = "<YOUR_INDEX_NAME>",
          Type = Enum.Parse<SearchTypeFacet>("Facet"),
          Facet = "theFacet",
        }
      ),
      new SearchQuery(
        new SearchForHits
        {
          IndexName = "<YOUR_INDEX_NAME>",
          Type = Enum.Parse<SearchTypeDefault>("Default"),
        }
      ),
    },
    Strategy = Enum.Parse<SearchStrategy>("StopIfEnoughMatches"),
  }
);

// print the response
Console.WriteLine(response);
// Initialize the client
final client =
    SearchClient(appId: 'ALGOLIA_APPLICATION_ID', apiKey: 'ALGOLIA_API_KEY');

// Call the API
final response = await client.search(
  searchMethodParams: SearchMethodParams(
    requests: [
      SearchForHits(
        indexName: "<YOUR_INDEX_NAME>",
      ),
      SearchForFacets(
        indexName: "<YOUR_INDEX_NAME>",
        type: SearchTypeFacet.fromJson("facet"),
        facet: "theFacet",
      ),
      SearchForHits(
        indexName: "<YOUR_INDEX_NAME>",
        type: SearchTypeDefault.fromJson("default"),
      ),
    ],
    strategy: SearchStrategy.fromJson("stopIfEnoughMatches"),
  ),
);

// print the response
print(response);
// Initialize the client
client, err := search.NewClient("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY")
if err != nil {
  // The client can fail to initialize if you pass an invalid parameter.
  panic(err)
}

// Call the API
response, err := client.Search(client.NewApiSearchRequest(

  search.NewEmptySearchMethodParams().SetRequests(
    []search.SearchQuery{*search.SearchForHitsAsSearchQuery(
      search.NewEmptySearchForHits().SetIndexName("<YOUR_INDEX_NAME>")), *search.SearchForFacetsAsSearchQuery(
      search.NewEmptySearchForFacets().SetIndexName("<YOUR_INDEX_NAME>").SetType(search.SearchTypeFacet("facet")).SetFacet("theFacet")), *search.SearchForHitsAsSearchQuery(
      search.NewEmptySearchForHits().SetIndexName("<YOUR_INDEX_NAME>").SetType(search.SearchTypeDefault("default")))}).SetStrategy(search.SearchStrategy("stopIfEnoughMatches"))))
if err != nil {
  // handle the eventual error
  panic(err)
}


// print the response
print(response)
// Initialize the client
SearchClient client = new SearchClient("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY");

// Call the API
SearchResponses response = client.search(
  new SearchMethodParams().setRequests(
    Arrays.asList(new SearchForHits().setIndexName("<YOUR_INDEX_NAME>").setQuery("<YOUR_QUERY>").setHitsPerPage(50))
  ),
  Hit.class
);

// print the response
System.out.println(response);
// Initialize the client
const client = algoliasearch('ALGOLIA_APPLICATION_ID', 'ALGOLIA_API_KEY');

// Call the API
const response = await client.search({
  requests: [
    { indexName: 'theIndexName' },
    { indexName: 'theIndexName2', type: 'facet', facet: 'theFacet' },
    { indexName: 'theIndexName', type: 'default' },
  ],
  strategy: 'stopIfEnoughMatches',
});


// print the response
console.log(response);
// Initialize the client
val client = SearchClient(appId = "ALGOLIA_APPLICATION_ID", apiKey = "ALGOLIA_API_KEY")

// Call the API
var response =
  client.search(
    searchMethodParams =
      SearchMethodParams(
        requests =
          listOf(
            SearchForHits(
              indexName = "<YOUR_INDEX_NAME>",
              query = "<YOUR_QUERY>",
              hitsPerPage = 50,
            )
          )
      )
  )


// print the response
println(response)
// Initialize the client
$client = SearchClient::create('ALGOLIA_APPLICATION_ID', 'ALGOLIA_API_KEY');

// Call the API
$response = $client->search(
    ['requests' => [
        ['indexName' => '<YOUR_INDEX_NAME>',
        ],

        ['indexName' => '<YOUR_INDEX_NAME>',
            'type' => 'facet',
            'facet' => 'theFacet',
        ],

        ['indexName' => '<YOUR_INDEX_NAME>',
            'type' => 'default',
        ],
    ],
        'strategy' => 'stopIfEnoughMatches',
    ],
);


// print the response
var_dump($response);
# Initialize the client
# In an asynchronous context, you can use SearchClient instead, which exposes the exact same methods.
client = SearchClientSync("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY")

# Call the API
response = client.search(
    search_method_params={
        "requests": [
            {
                "indexName": "<YOUR_INDEX_NAME>",
            },
            {
                "indexName": "<YOUR_INDEX_NAME>",
                "type": "facet",
                "facet": "theFacet",
            },
            {
                "indexName": "<YOUR_INDEX_NAME>",
                "type": "default",
            },
        ],
        "strategy": "stopIfEnoughMatches",
    },
)


# print the response
print(response)
# Initialize the client
client = Algolia::SearchClient.create("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY")

# Call the API
response = client.search(
  Algolia::Search::SearchMethodParams.new(
    requests: [
      Algolia::Search::SearchForHits.new(index_name: "<YOUR_INDEX_NAME>"),
      Algolia::Search::SearchForFacets.new(index_name: "<YOUR_INDEX_NAME>", type: "facet", facet: "theFacet"),
      Algolia::Search::SearchForHits.new(index_name: "<YOUR_INDEX_NAME>", type: "default")
    ],
    strategy: "stopIfEnoughMatches"
  )
)


# print the response
puts(response)
// Initialize the client
val client = SearchClient(appId = "ALGOLIA_APPLICATION_ID", apiKey = "ALGOLIA_API_KEY")

// Call the API
val response = Await.result(
  client.search(
    searchMethodParams = SearchMethodParams(
      requests = Seq(
        SearchForHits(
          indexName = "<YOUR_INDEX_NAME>"
        ),
        SearchForFacets(
          indexName = "<YOUR_INDEX_NAME>",
          `type` = SearchTypeFacet.withName("facet"),
          facet = "theFacet"
        ),
        SearchForHits(
          indexName = "<YOUR_INDEX_NAME>",
          `type` = Some(SearchTypeDefault.withName("default"))
        )
      ),
      strategy = Some(SearchStrategy.withName("stopIfEnoughMatches"))
    )
  ),
  Duration(100, "sec")
)

// print the response
println(response)
// Initialize the client
let client = try SearchClient(appID: "ALGOLIA_APPLICATION_ID", apiKey: "ALGOLIA_API_KEY")

// Call the API
let response: SearchResponses<Hit> = try await client.search(searchMethodParams: SearchMethodParams(
    requests: [
        SearchQuery.searchForHits(SearchForHits(indexName: "<YOUR_INDEX_NAME>")),
        SearchQuery.searchForFacets(SearchForFacets(
            facet: "theFacet",
            indexName: "<YOUR_INDEX_NAME>",
            type: SearchTypeFacet.facet
        )),
        SearchQuery.searchForHits(SearchForHits(
            indexName: "<YOUR_INDEX_NAME>",
            type: SearchTypeDefault.`default`
        )),
    ],
    strategy: SearchStrategy.stopIfEnoughMatches
))

// print the response
print(response)

See the full API reference

For more details about input parameters and response fields.
Last modified on April 30, 2026