Skip to main content
Latest version: Install version 7 of the C#/.NET API clients by adding the 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.
The C#/.NET API clients are open source and generated from OpenAPI specifications.

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.
1

Create account

If you haven’t already, create an Algolia account.
2

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.
3

Run code

Run the code, depending on your development environment.
# 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
If the command is successful, you’ll see the API response as a native object in your programming language.
Last modified on June 10, 2026