- C#
- Dart
- Go
- Java
- JavaScript
- Kotlin
- PHP
- Python
- Ruby
- Scala
- Swift
Latest version: Install version 7 of the C#/.NET API clients by adding the The C#/.NET API clients are open source and generated from OpenAPI specifications.
Algolia.Search package from NuGet.
For example:Command line
dotnet add package Algolia.Search --version "7.*"
Building ASP.NET apps?
Check the additional information about dependency injection.
Latest version: Install version 1 the Dart API clients by adding the The Dart API clients are open source and generated from OpenAPI specifications.
algoliasearch package as a dependency to your project.Command line
dart pub add algoliasearch:'^1.0'
Latest version: Install version 4 of the Go API clients by adding the The Go API clients are open source and generated from OpenAPI specifications.
algoliasearch-client-go package as a dependency to your module.Command line
go get github.com/algolia/algoliasearch-client-go/v4
Latest version: Install version 4 of the Java API clients by adding the following dependencies to your project.
For Maven, add the following dependencies to your For Gradle, add the following dependencies to your Replace
pom.xml file:pom.xml
<dependency>
<groupId>com.algolia</groupId>
<artifactId>algoliasearch</artifactId>
<version>VERSION</version>
</dependency>
build.gradle file:build.gradle
dependencies {
implementation 'com.algolia:algoliasearch:VERSION'
}
VERSION with the version of the API clients you want to install.
You can find the available releases on Maven Central.If you don’t use Maven or Gradle,
you can download the JAR files.The Java API clients are open source and generated from OpenAPI specifications.Latest version: To install version 5 of the JavaScript API clients, add the The The JavaScript API clients are open source and generated from OpenAPI specifications.Use the lite client if you only need search operations in client-side code:
algoliasearch package as a dependency to your project.npm install algoliasearch@5
yarn add algoliasearch@5
pnpm add algoliasearch@5
algoliasearch package includes API clients for the Search API,
the Personalization API, the Analytics API,
and the A/B testing API.
If you only need to access methods from a specific API, you can install API clients separately:# Search API
npm install @algolia/client-search
# Recommend API
npm install @algolia/recommend
# Analytics API
npm install @algolia/client-analytics
# A/B testing API
npm install @algolia/client-abtesting
# Ingestion API
npm install @algolia/ingestion
# Insights API
npm install @algolia/client-insights
# Monitoring
npm install @algolia/monitoring
# Personalization API
npm install @algolia/client-personalization
# Query Suggestions API
npm install @algolia/client-query-suggestions
# Usage API
npm install @algolia/client-usage
# Search API
yarn add @algolia/client-search
# Recommend API
yarn add @algolia/recommend
# Analytics API
yarn add @algolia/client-analytics
# A/B testing API
yarn add @algolia/client-abtesting
# Ingestion API
yarn add @algolia/ingestion
# Insights API
yarn add @algolia/client-insights
# Monitoring
yarn add @algolia/monitoring
# Personalization API
yarn add @algolia/client-personalization
# Query Suggestions API
yarn add @algolia/client-query-suggestions
# Usage API
yarn add @algolia/client-usage
pnpm add @algolia/client-search
# Recommend API
pnpm add @algolia/recommend
# Analytics API
pnpm add @algolia/client-analytics
# A/B testing API
pnpm add @algolia/client-abtesting
# Ingestion API
pnpm add @algolia/ingestion
# Insights API
pnpm add @algolia/client-insights
# Monitoring
pnpm add @algolia/monitoring
# Personalization API
pnpm add @algolia/client-personalization
# Query Suggestions API
pnpm add @algolia/client-query-suggestions
# Usage API
pnpm add @algolia/client-usage
Load the JavaScript API client from a CDN
To load the JavaScript API client from a content delivery network, such as jsDelivr, add one of the following snippets to the<head> element of your page.Use the full client if you need indexing, settings, Rules, synonyms, or other management operations:HTML
<script
src="https://cdn.jsdelivr.net/npm/algoliasearch@5.55.2/dist/algoliasearch.umd.js"
integrity="sha256-W1cOGLqpmXPQx/PgekLq8qeoKHL/WgJ9QD7GjdsTMbA="
crossorigin="anonymous"
></script>
HTML
<script
src="https://cdn.jsdelivr.net/npm/algoliasearch@5.55.2/dist/lite/builds/browser.umd.js"
integrity="sha256-lv0Up18USw4x5UzP9OQ3Swr4G06aXz0ACDRQgAZO/Uk="
crossorigin="anonymous"
></script>
Latest version: To install version 3 of the Kotlin API clients, add the following
dependencies to your The Kotlin API clients are open source and generated from OpenAPI specifications.
build.gradle file:build.gradle
repositories {
mavenCentral()
}
dependencies {
implementation 'com.algolia:algoliasearch-client-kotlin:ALGOLIA_VERSION'
// You need to specify a Ktor engine suitable for your platform
runtimeOnly 'io.ktor:ktor-client-java:KTOR_VERSION'
}
-
Replace
ALGOLIA_VERSIONwith the version of the Kotlin API client you want to install. You can find the released versions on Maven Central. -
Replace
KTOR_VERSIONwith the version of the Ktor client you want to use. To learn more about the available engines, see Client engines.
build.gradle
repositories {
mavenCentral()
}
dependencies {
implementation platform("com.algolia:algoliasearch-client-kotlin-bom:ALGOLIA_VERSION")
// define dependencies without versions
implementation 'com.algolia:algoliasearch-client-kotlin'
runtimeOnly 'io.ktor:ktor-client-java'
}
Latest version: To install version 4 of the PHP API clients,
install the The PHP API clients are open source and generated from OpenAPI specifications.
algoliasearch-client-php package with with composer.Command line
composer require algolia/algoliasearch-client-php "^4.0"
Building Laravel apps?
Check the Laravel integration built on top of the PHP API client.
Building Symfony apps?
Check the Symfony integration built on top of the PHP API client.
Latest version: To install version 4 of the Python API clients, install the The Python API clients are open source and generated from OpenAPI specifications.
algoliasearch package.
The Python API clients support Python 3.8 or later.Command line
pip install "algoliasearch>=4,<5"
Building Django apps?
Check the Django integration built on top of the Python API client.
Latest version: To install version 3 of the Ruby API clients,
add the The Ruby API clients are open source and generated from OpenAPI specifications.
algolia gem as a dependency to your project.
The Ruby API clients support Ruby 2.2 or later.Command line
bundle add algolia --version='~>3.0'
# or: gem install algolia -v '~>3.0'
Building Ruby on Rails apps?
Check the Ruby on Rails integration built on top of the Ruby API client.
Latest version: To install version 2 of the Scala API clients,
add the following dependencies to your Replace
build.sbt file:build.sbt
libraryDependencies += "com.algolia" %% "algoliasearch-scala" % "VERSION"
VERSION with the version of the API clients you want to install.
You can find the available releases on Maven Central:The Scala API clients are open source and generated from OpenAPI specifications.Latest version: To install version 9 of the Swift API clients,
add the With CocoaPods, add the following to your With Carthage, add the following to your The Swift API clients are open source and generated from OpenAPI specifications.
algoliasearch-client-swift package as a dependency to your project.With the Swift Package Manager,
add the following dependencies to your Package.swift file:Swift
let package = Package(
// ...
dependencies: [
.package(url: "https://github.com/algolia/algoliasearch-client-swift.git", from: "9.0.0")
],
targets: [
.target(
// ...
dependencies: [
.product(name: "Search", package: "algoliasearch-client-swift")
]
)
]
)
Podfile:Podfile
pod("AlgoliaSearchClient", "~> 9.0.0")
Cartfile:Cartfile
github "algolia/algoliasearch-client-swift" ~> 9.0.0
Test your installation
To test your installation, try running a short program that adds a record to a test index, searches your index, and prints the results.Create account
If you haven’t already, create an Algolia account.
Copy code
Copy the following code into a new project or file.
Replace
ALGOLIA_APPLICATION_ID and ALGOLIA_API_KEY with values from your account.
Make sure to use an API key with addObject and search permissions.using Algolia.Search.Clients;
using Algolia.Search.Models.Search;
var appID = "ALGOLIA_APPLICATION_ID";
// API key with `addObject` and `search` ACL
var apiKey = "ALGOLIA_API_KEY";
var indexName = "test-index";
var client = new SearchClient(appID, apiKey);
// Create a new record
var record = new Dictionary<string, string>
{
{ "objectID", "object-1" },
{ "name", "test record" },
};
// Add record to an index
var saveResp = await client.SaveObjectAsync(indexName, record);
// Wait until indexing is done
await client.WaitForTaskAsync(indexName, saveResp.TaskID);
// Search for 'test'
var searchResp = await client.SearchAsync<Object>(
new SearchMethodParams
{
Requests = new List<SearchQuery>
{
new SearchQuery(new SearchForHits { IndexName = indexName, Query = "test" })
}
}
);
Console.WriteLine(searchResp.ToJson());
// File: helloAlgolia.dart
import 'package:algoliasearch/algoliasearch.dart';
Future<void> main() async {
final appID = "ALGOLIA_APPLICATION_ID";
final apiKey = "ALGOLIA_API_KEY";
final indexName = "test-index";
final client = SearchClient(appId: appID, apiKey: apiKey);
// Create a new record
final record = {'objectID': 'object-1', 'name': 'test record'};
// Add the record to an index
final saveResp = await client.saveObject(indexName: indexName, body: record);
// Wait until the indexing is done
await client.waitTask(indexName: indexName, taskID: saveResp.taskID);
// Search for 'test'
final searchResp = await client.search(
searchMethodParams: SearchMethodParams(
requests: [SearchForHits(indexName: indexName, query: 'test')],
),
);
print(searchResp.toJson());
}
// File: helloAlgolia.go
package main
import (
"fmt"
"github.com/algolia/algoliasearch-client-go/v4/algolia/search"
)
func main() {
appID := "ALGOLIA_APPLICATION_ID"
// API key with `addObject` and `search` ACL
apiKey := "ALGOLIA_API_KEY"
indexName := "test-index"
record := map[string]any{
"objectID": "object-1",
"name": "test record",
}
client, err := search.NewClient(appID, apiKey)
if err != nil {
panic(err)
}
// Add record to an index
saveResp, err := client.SaveObject(
client.NewApiSaveObjectRequest(indexName, record),
)
if err != nil {
panic(err)
}
// Wait until indexing is done
_, err = client.WaitForTask(indexName, saveResp.TaskID)
if err != nil {
panic(err)
}
// Search for 'test'
searchResp, err := client.Search(
client.NewApiSearchRequest(
search.NewEmptySearchMethodParams().SetRequests(
[]search.SearchQuery{
*search.SearchForHitsAsSearchQuery(
search.NewEmptySearchForHits().SetIndexName(indexName).SetQuery("test"),
),
},
),
),
)
if err != nil {
panic(err)
}
fmt.Println(searchResp.Results)
}
package com.algolia.example;
import com.algolia.api.SearchClient;
import com.algolia.model.search.SearchForHits;
import com.algolia.model.search.SearchMethodParams;
import java.util.HashMap;
public class Main {
public static void main(String[] args) {
final var appID = "ALGOLIA_APPLICATION_ID";
// API key with `addObject` and `search` ACL
final var apiKey = "ALGOLIA_API_KEY";
final var indexName = "test-index";
try (var client = new SearchClient(appID, apiKey)) {
// Create a new record
var body = new HashMap<>();
body.put("objectID", "object-1");
body.put("name", "test record");
// Add the record to an index
var addResponse = client.saveObject(indexName, body);
// Wait until indexing is done
client.waitForTask(indexName, addResponse.getTaskID());
// Search for 'test'
var responses = client.search(
new SearchMethodParams().addRequests(
new SearchForHits()
.setIndexName(indexName)
.setQuery("test")
), body.getClass());
System.out.println(responses);
} catch (Exception e) {
e.printStackTrace();
}
}
}
// helloAlgolia.mjs
import { algoliasearch } from "algoliasearch";
const appID = "ALGOLIA_APPLICATION_ID";
// API key with `addObject` and `editSettings` ACL
const apiKey = "ALGOLIA_API_KEY";
const indexName = "test-index";
const client = algoliasearch(appID, apiKey);
const record = { objectID: "object-1", name: "test record" };
// Add record to an index
const { taskID } = await client.saveObject({
indexName,
body: record,
});
// Wait until indexing is done
await client.waitForTask({
indexName,
taskID,
});
// Search for "test"
const { results } = await client.search({
requests: [
{
indexName,
query: "test",
},
],
});
console.log(JSON.stringify(results));
package org.example
import com.algolia.client.api.SearchClient
import com.algolia.client.extensions.waitForTask
import com.algolia.client.model.search.*
suspend fun main() {
val appID = "ALGOLIA_APPLICATION_ID"
// API key with `addObject` and `search` ACL
val apiKey = "ALGOLIA_API_KEY"
val indexName = "INDEX_NAME"
val client = SearchClient(appID, apiKey)
// Create record (with autogenerated `objectID`)
val record = buildJsonObject {
put("objectID", "object-1")
put("name", "test record")
}
// Add record to an index
val addResponse = client.saveObject(indexName, record)
// Wait until indexing is done
client.waitForTask(indexName, addResponse.taskID)
// Search for 'test'
val response = client.search(
SearchMethodParams(requests =
listOf(
SearchForHits(
indexName,
query = "test"
)
)
)
)
println(response)
}
<?php
// helloAlgolia.php
require_once realpath(__DIR__ . "/vendor/autoload.php");
use Algolia\AlgoliaSearch\Api\SearchClient;
$appID = "ALGOLIA_APPLICATION_ID";
// API key with `addObject` and `search` ACL
$apiKey = "ALGOLIA_API_KEY";
$indexName = "test-index";
$client = SearchClient::create($appID, $apiKey);
// Create a new record
$record = [
"objectID" => "object-1",
"name" => "test record",
];
// Add the record to an index
$saveResp = $client->saveObject($indexName, $record);
// Wait until indexing is done
$client->waitForTask($indexName, $saveResp['taskID']);
// Search for 'test'
$searchResponse = $client->search(
['requests' => [
['indexName' => $indexName, 'query' => 'test']
]],
);
echo json_encode($searchResponse);
# hello_algolia.py
from algoliasearch.search.client import SearchClientSync
app_id = "ALGOLIA_APPLICATION_ID"
# API key with `addObject` and `search` ACL
api_key = "ALGOLIA_API_KEY"
index_name = "test-index"
if __name__ == "__main__":
client = SearchClientSync(app_id, api_key)
record = {"objectID": "object-1", "name": "test record"}
# Add record to an index
save_resp = client.save_object(
index_name=index_name,
body=record,
)
# Wait until indexing is done
client.wait_for_task(
index_name=index_name,
task_id=save_resp.task_id,
)
# Search for 'test'
results = client.search({"requests": [{"indexName": index_name, "query": "test"}]})
print(results.to_json())
# hello_algolia.rb
require "algolia"
app_id = "ALGOLIA_APPLICATION_ID"
# API key with `addObject` and `search` ACL
api_key = "ALGOLIA_API_KEY"
index_name = "test-index"
client = Algolia::SearchClient.create(app_id, api_key)
record = {objectID: "object-1", name: "test record"}
# Add record to an index
save_resp = client.save_object(
index_name = index_name,
body = record
)
# Wait until indexing is done
client.wait_for_task(
index_name = index_name,
task_id = save_resp.task_id
)
# Search for 'test'
results = client.search(
search_method_params = {
requests: [{indexName: index_name, query: "test"}]
}
)
puts(results.to_json)
package com.algolia.example
import scala.concurrent.Await
import scala.concurrent.duration._
import scala.concurrent.ExecutionContext.Implicits.global
import algoliasearch.api.SearchClient
import algoliasearch.extension.SearchClientExtensions
import algoliasearch.search.{SearchForHits, SearchMethodParams}
import org.json4s.{JField, JObject, JString}
@main
def main(): Unit = {
val appId = "ALGOLIA_APPLICATION_ID"
// API key with `addObject` and `search` ACL
val apiKey = "ALGOLIA_API_KEY"
val indexName = "test-index"
val client = SearchClient(appId, apiKey)
// Create a new record
val record = JObject(
List(
JField("objectID", JString("object-1")),
JField("name", JString("test record"))
)
)
// Add the record to an index
val saveFuture = client.saveObject(
indexName,
body = record
)
// Block the execution until future is resolved
val saveResponse = Await.result(saveFuture, 100.seconds)
// Wait until indexing is done
client.waitTask(indexName, resolvedResponse.taskID)
// Search for 'test'
val searchFuture = client.search(
searchMethodParams = SearchMethodParams(
requests = Seq(
SearchForHits(
indexName,
query = Some("test"),
)
)
)
)
val searchResponse = Await.result(searchFuture, 100.seconds)
println(searchResponse)
}
// main.swift
@preconcurrency import Search
let appID = "ALGOLIA_APPLICATION_ID"
// API key with `addObject` and `search` ACL
let apiKey = "ALGOLIA_API_KEY"
let indexName = "test-index"
let client = try SearchClient(appID: appID, apiKey: apiKey)
// Create a new record
let record = ["objectID": "object-1", "name": "test-record"]
// Add the record to an index
let saveResp = try await client.saveObject(
indexName: indexName,
body: record
)
// Wait until indexing is done
try await client.waitForTask(
with: saveResp.taskID,
in: indexName
)
// Search for 'test'
let searchResp: SearchResponses<Hit> = try await client.search(
searchMethodParams: SearchMethodParams(
requests: [
SearchQuery.searchForHits(
SearchForHits(
query: "test",
indexName: indexName
)
)
]
)
)
print(searchResp)
In production, use environment variables for your credentials.
Run code
Run the code, depending on your development environment.If the command is successful,
you’ll see the API response as a native object in your programming language.
# For example:
dotnet run
dart run
go run helloAlgolia.go
Depending on your development environment,
build and run the project.
node helloAlgolia.js
Depending on your development environment,
build and run the project.
php helloAlgolia.php
python hello_algolia.py
ruby hello_algolia.rb
sbt run
swift run