Migration guide
The amount of changes in this new version is significant. If you were using a version older than v4, please also read this migration guide.
You should thoroughly test your application before deploying to production.
This document lists every known breaking change, not all of them may affect your application.
Common breaking changes
The changes below are effective on all of the API clients.
initIndex
Methods previously available at the initIndex
level are now available at the root
level of the API client.
The indexName
parameter is now required when calling those methods.
- C#
- Dart
- Go
- Java
- JavaScript
- Kotlin
- PHP
- Python
- Ruby
- Scala
- Swift
using Algolia.Search.Clients;
using Algolia.Search.Http;
var client = new SearchClient(new SearchConfig("YOUR_APP_ID", "YOUR_API_KEY"));
var response = await client.SearchAsync<Object>(
new SearchMethodParams
{
Requests = new List<SearchQuery>
{
new SearchQuery(
new SearchForHits
{
IndexName = "<YOUR_INDEX_NAME>",
Query = "<YOUR_QUERY>",
HitsPerPage = 50,
}
)
},
}
);
import 'package:algolia_client_search/algolia_client_search.dart';
final client = SearchClient(appId: 'YOUR_APP_ID', apiKey: 'YOUR_API_KEY');
final response = await client.search(
searchMethodParams: SearchMethodParams(
requests: [
SearchForHits(
indexName: "<YOUR_INDEX_NAME>",
query: "<YOUR_QUERY>",
hitsPerPage: 50,
),
],
),
);
import "github.com/algolia/algoliasearch-client-go/v4/algolia/search"
client, err := search.NewClient("YOUR_APP_ID", "YOUR_API_KEY")
response, err := client.Search(client.NewApiSearchRequest(
search.NewEmptySearchMethodParams().SetRequests(
[]search.SearchQuery{*search.SearchForHitsAsSearchQuery(
search.NewEmptySearchForHits().SetIndexName("<YOUR_INDEX_NAME>").SetQuery("<YOUR_QUERY>").SetHitsPerPage(50))}),
))
if err != nil {
// handle the eventual error
panic(err)
}
// use the model directly
print(response)
import com.algolia.api.SearchClient;
import com.algolia.model.search.*;
SearchClient client = new SearchClient("YOUR_APP_ID", "YOUR_API_KEY");
client.search(
new SearchMethodParams()
.setRequests(List.of(new SearchForHits().setIndexName("<YOUR_INDEX_NAME>").setQuery("<YOUR_QUERY>").setHitsPerPage(50))),
Hit.class
);
import { searchClient } from '@algolia/client-search';
const client = searchClient('YOUR_APP_ID', 'YOUR_API_KEY');
const response = await client.search({
requests: [
{
indexName: '<YOUR_INDEX_NAME>',
query: '<YOUR_QUERY>',
hitsPerPage: 50,
},
],
});
// use typed response
console.log(response);
import com.algolia.client.api.SearchClient
val client = SearchClient(appId = "YOUR_APP_ID", apiKey = "YOUR_API_KEY")
var response = client.search(
searchMethodParams = SearchMethodParams(
requests = listOf(
SearchForHits(
indexName = "<YOUR_INDEX_NAME>",
query = "<YOUR_QUERY>",
hitsPerPage = 50,
),
),
),
)
// Use the response
println(response)
use Algolia\AlgoliaSearch\Api\SearchClient;
$client = SearchClient::create('<YOUR_APP_ID>', '<YOUR_API_KEY>');
$response = $client->search(
['requests' => [
['indexName' => '<YOUR_INDEX_NAME>',
'query' => '<YOUR_QUERY>',
'hitsPerPage' => 50,
],
],
],
);
// play with the response
var_dump($response);
from algoliasearch.search.client import SearchClient
_client = SearchClient("YOUR_APP_ID", "YOUR_API_KEY")
response = await _client.search(
search_method_params={
"requests": [
{
"indexName": "<YOUR_INDEX_NAME>",
"query": "<YOUR_QUERY>",
"hitsPerPage": 50,
},
],
},
)
# use the class directly
print(response)
# print the JSON response
print(response.to_json())
require 'algolia'
client = Algolia::SearchClient.create('YOUR_APP_ID', 'YOUR_API_KEY')
response = client.search(
SearchMethodParams.new(
requests: [SearchForHits.new(
index_name: "<YOUR_INDEX_NAME>", query: "<YOUR_QUERY>", hits_per_page: 50
)]
)
)
# use the class directly
puts response
# print the JSON response
puts response.to_json
import algoliasearch.api.SearchClient
val client = SearchClient(appId = "YOUR_APP_ID", apiKey = "YOUR_API_KEY")
val response = client.search(
searchMethodParams = SearchMethodParams(
requests = Seq(
SearchForHits(
indexName = "<YOUR_INDEX_NAME>",
query = Some("<YOUR_QUERY>"),
hitsPerPage = Some(50)
)
)
)
)
// Use the response
val value = Await.result(response, Duration(100, "sec"))
import Search
let client = try SearchClient(appID: "YOUR_APP_ID", apiKey: "YOUR_API_KEY")
let response: SearchResponses<Hit> = try await client
.search(searchMethodParams: SearchMethodParams(requests: [SearchQuery.searchForHits(SearchForHits(
query: "<YOUR_QUERY>",
hitsPerPage: 50,
indexName: "<YOUR_INDEX_NAME>"
))]))
A/B testing client
The A/B testing methods were previously available under the Analytics
client, we’ve decided to make a client out of it to split concerns.
The Abtesting
client now hosts all of the A/B testing
related methods.
- C#
- Dart
- Go
- Java
- JavaScript
- Kotlin
- PHP
- Python
- Ruby
- Scala
- Swift
using Algolia.Search.Clients;
using Algolia.Search.Http;
var client = new AbtestingClient(
var response = await client.GetABTestAsync(42);
abtesting.import is not implemented in dart
abtesting.init is not implemented in dart
abtesting.getABTest is not implemented in dart
import "github.com/algolia/algoliasearch-client-go/v4/algolia/abtesting"
abtesting.init is not implemented in go
// Initialize the client with your application region, eg. abtesting.YOUR_APP_ID_REGION
client, err := abtesting.NewClient("YOUR_APP_ID", "YOUR_API_KEY", abtesting.US)
if err != nil {
// The client can fail to initialize if you pass an invalid parameter.
panic(err)
}
// Call the API
response, err := client.GetABTest(client.NewApiGetABTestRequest(
42,
))
if err != nil {
// handle the eventual error
panic(err)
}
// use the model directly
print(response)
import com.algolia.api.AbtestingClient;
import com.algolia.model.abtesting.*;
AbtestingClient client = new AbtestingClient("YOUR_APP_ID", "YOUR_API_KEY", "YOUR_APP_ID_REGION");
client.getABTest(42);
import { abtestingClient } from '@algolia/client-abtesting';
const client = abtestingClient(
const response = await client.getABTest({ id: 42 });
// use typed response
console.log(response);
import com.algolia.client.api.AbtestingClient
val client = AbtestingClient(appId = "YOUR_APP_ID", apiKey = "YOUR_API_KEY", region = "YOUR_APP_ID_REGION")
var response = client.getABTest(
id = 42,
)
// Use the response
println(response)
use Algolia\AlgoliaSearch\Api\AbtestingClient;
$client = AbtestingClient::create('<YOUR_APP_ID>', '<YOUR_API_KEY>', 'YOUR_APP_ID_REGION');
$response = $client->getABTest(
42,
);
// play with the response
var_dump($response);
from algoliasearch.abtesting.client import AbtestingClient
_client = AbtestingClient("YOUR_APP_ID", "YOUR_API_KEY", "YOUR_APP_ID_REGION")
response = await _client.get_ab_test(
id=42,
)
# use the class directly
print(response)
# print the JSON response
print(response.to_json())
require 'algolia'
client = Algolia::AbtestingClient.create('YOUR_APP_ID', 'YOUR_API_KEY', 'YOUR_APP_ID_REGION')
response = client.get_ab_test(42)
# use the class directly
puts response
# print the JSON response
puts response.to_json
import algoliasearch.api.AbtestingClient
val client = AbtestingClient(appId = "YOUR_APP_ID", apiKey = "YOUR_API_KEY", region = Option("YOUR_APP_ID_REGION"))
val response = client.getABTest(
id = 42
)
// Use the response
val value = Await.result(response, Duration(100, "sec"))
import Abtesting
let client = try AbtestingClient(appID: "YOUR_APP_ID", apiKey: "YOUR_API_KEY", region: .us)
let response = try await client.getABTest(id: 42)
wait
The chainable wait
method that was available on a few methods has been replaced with an helper called waitForTask
.
You can now optionally configure how the wait logic behaves by passing the taskID
returned when calling the Algolia API.
Read more in our dedicated guide
- C#
- Dart
- Go
- Java
- JavaScript
- Kotlin
- PHP
- Python
- Ruby
- Scala
- Swift
using Algolia.Search.Clients;
using Algolia.Search.Http;
var client = new SearchClient(new SearchConfig("YOUR_APP_ID", "YOUR_API_KEY"));
var response = await client.SaveObjectAsync(
"<YOUR_INDEX_NAME>",
new Dictionary<string, string> { { "objectID", "id" }, { "test", "val" } }
);
await client.WaitForTaskAsync("<YOUR_INDEX_NAME>", response.TaskID);
import 'package:algolia_client_search/algolia_client_search.dart';
final client = SearchClient(appId: 'YOUR_APP_ID', apiKey: 'YOUR_API_KEY');
final response = await client.saveObject(
indexName: "<YOUR_INDEX_NAME>",
body: {
'objectID': "id",
'test': "val",
},
);
await client.waitTask('<YOUR_INDEX_NAME>', response.taskID);
import "github.com/algolia/algoliasearch-client-go/v4/algolia/search"
client, err := search.NewClient("YOUR_APP_ID", "YOUR_API_KEY")
response, err := client.SaveObject(client.NewApiSaveObjectRequest(
"<YOUR_INDEX_NAME>", map[string]any{"objectID": "id", "test": "val"},
))
if err != nil {
// handle the eventual error
panic(err)
}
// use the model directly
print(response)
taskResponse, err := searchClient.WaitForTask("<YOUR_INDEX_NAME>", response.TaskID, nil, nil, nil)
if err != nil {
panic(err)
}
import com.algolia.api.SearchClient;
import com.algolia.model.search.*;
SearchClient client = new SearchClient("YOUR_APP_ID", "YOUR_API_KEY");
client.saveObject("<YOUR_INDEX_NAME>", Map.of("objectID", "id", "test", "val"));
client.waitForTask("<YOUR_INDEX_NAME>", response.getTaskID());
import { searchClient } from '@algolia/client-search';
const client = searchClient('YOUR_APP_ID', 'YOUR_API_KEY');
const response = await client.saveObject({
indexName: '<YOUR_INDEX_NAME>',
body: { objectID: 'id', test: 'val' },
});
// use typed response
console.log(response);
await client.waitForTask({ indexName: '<YOUR_INDEX_NAME>', taskID: response.taskID });
import com.algolia.client.api.SearchClient
val client = SearchClient(appId = "YOUR_APP_ID", apiKey = "YOUR_API_KEY")
var response = client.saveObject(
indexName = "<YOUR_INDEX_NAME>",
body = buildJsonObject {
put(
"objectID",
JsonPrimitive("id"),
)
put(
"test",
JsonPrimitive("val"),
)
},
)
// Use the response
println(response)
client.waitTask("<YOUR_INDEX_NAME>", response.taskID)
use Algolia\AlgoliaSearch\Api\SearchClient;
$client = SearchClient::create('<YOUR_APP_ID>', '<YOUR_API_KEY>');
$response = $client->saveObject(
'<YOUR_INDEX_NAME>',
['objectID' => 'id',
'test' => 'val',
],
);
// play with the response
var_dump($response);
$client->waitForTask('<YOUR_INDEX_NAME>', $response['taskID']);
from algoliasearch.search.client import SearchClient
_client = SearchClient("YOUR_APP_ID", "YOUR_API_KEY")
response = await _client.save_object(
index_name="<YOUR_INDEX_NAME>",
body={
"objectID": "id",
"test": "val",
},
)
# use the class directly
print(response)
# print the JSON response
print(response.to_json())
await client.wait_for_task(index_name="<YOUR_INDEX_NAME>", task_id=response.task_id)
require 'algolia'
client = Algolia::SearchClient.create('YOUR_APP_ID', 'YOUR_API_KEY')
response = client.save_object("<YOUR_INDEX_NAME>", { objectID: "id", test: "val" })
# use the class directly
puts response
# print the JSON response
puts response.to_json
client.wait_for_task("<YOUR_INDEX_NAME>", response.task_id)
import algoliasearch.api.SearchClient
val client = SearchClient(appId = "YOUR_APP_ID", apiKey = "YOUR_API_KEY")
val response = client.saveObject(
indexName = "<YOUR_INDEX_NAME>",
body = JObject(List(JField("objectID", JString("id")), JField("test", JString("val"))))
)
// Use the response
val value = Await.result(response, Duration(100, "sec"))
client.waitTask("<YOUR_INDEX_NAME>", response.getTaskID())
import Search
let client = try SearchClient(appID: "YOUR_APP_ID", apiKey: "YOUR_API_KEY")
let response = try await client.saveObject(
indexName: "<YOUR_INDEX_NAME>",
body: ["objectID": "id", "test": "val"]
)
try await client.waitForTask(with: response.taskID, in: "<YOUR_INDEX_NAME>")
moveIndex
/copyIndex
The operationIndex
allows you to either copy
or move
a source
index to a destination
index within the same Algolia application.
You can also decide what scope
of the source
index should be copied, read more in our dedicated guide.
This method can be used as a replacement for the copyRules
, copySynonyms
, and copySettings
method when using the associated scope
.
- C#
- Dart
- Go
- Java
- JavaScript
- Kotlin
- PHP
- Python
- Ruby
- Scala
- Swift
using Algolia.Search.Clients;
using Algolia.Search.Http;
var client = new SearchClient(new SearchConfig("YOUR_APP_ID", "YOUR_API_KEY"));
var response = await client.OperationIndexAsync(
"<SOURCE_INDEX_NAME>",
new OperationIndexParams
{
Operation = Enum.Parse<OperationType>("Move"),
Destination = "<DESTINATION_INDEX_NAME>",
Scope = new List<ScopeType>
{
Enum.Parse<ScopeType>("Rules"),
Enum.Parse<ScopeType>("Settings")
},
}
);
await client.WaitForTaskAsync("<SOURCE_INDEX_NAME>", response.TaskID);
import 'package:algolia_client_search/algolia_client_search.dart';
final client = SearchClient(appId: 'YOUR_APP_ID', apiKey: 'YOUR_API_KEY');
final response = await client.operationIndex(
indexName: "<SOURCE_INDEX_NAME>",
operationIndexParams: OperationIndexParams(
operation: OperationType.fromJson("move"),
destination: "<DESTINATION_INDEX_NAME>",
scope: [
ScopeType.fromJson("rules"),
ScopeType.fromJson("settings"),
],
),
);
await client.waitTask('<SOURCE_INDEX_NAME>', response.taskID);
import "github.com/algolia/algoliasearch-client-go/v4/algolia/search"
client, err := search.NewClient("YOUR_APP_ID", "YOUR_API_KEY")
response, err := client.OperationIndex(client.NewApiOperationIndexRequest(
"<SOURCE_INDEX_NAME>",
search.NewEmptyOperationIndexParams().SetOperation(search.OperationType("move")).SetDestination("<DESTINATION_INDEX_NAME>").SetScope(
[]search.ScopeType{search.ScopeType("rules"), search.ScopeType("settings")}),
))
if err != nil {
// handle the eventual error
panic(err)
}
// use the model directly
print(response)
taskResponse, err := searchClient.WaitForTask("<SOURCE_INDEX_NAME>", response.TaskID, nil, nil, nil)
if err != nil {
panic(err)
}
import com.algolia.api.SearchClient;
import com.algolia.model.search.*;
SearchClient client = new SearchClient("YOUR_APP_ID", "YOUR_API_KEY");
client.operationIndex(
"<SOURCE_INDEX_NAME>",
new OperationIndexParams()
.setOperation(OperationType.MOVE)
.setDestination("<DESTINATION_INDEX_NAME>")
.setScope(List.of(ScopeType.RULES, ScopeType.SETTINGS))
);
client.waitForTask("<SOURCE_INDEX_NAME>", response.getTaskID());
import { searchClient } from '@algolia/client-search';
const client = searchClient('YOUR_APP_ID', 'YOUR_API_KEY');
const response = await client.operationIndex({
indexName: '<SOURCE_INDEX_NAME>',
operationIndexParams: {
operation: 'move',
destination: '<DESTINATION_INDEX_NAME>',
scope: ['rules', 'settings'],
},
});
// use typed response
console.log(response);
await client.waitForTask({ indexName: '<SOURCE_INDEX_NAME>', taskID: response.taskID });
import com.algolia.client.api.SearchClient
val client = SearchClient(appId = "YOUR_APP_ID", apiKey = "YOUR_API_KEY")
var response = client.operationIndex(
indexName = "<SOURCE_INDEX_NAME>",
operationIndexParams = OperationIndexParams(
operation = OperationType.entries.first { it.value == "move" },
destination = "<DESTINATION_INDEX_NAME>",
scope = listOf(ScopeType.entries.first { it.value == "rules" }, ScopeType.entries.first { it.value == "settings" }),
),
)
// Use the response
println(response)
client.waitTask("<SOURCE_INDEX_NAME>", response.taskID)
use Algolia\AlgoliaSearch\Api\SearchClient;
$client = SearchClient::create('<YOUR_APP_ID>', '<YOUR_API_KEY>');
$response = $client->operationIndex(
'<SOURCE_INDEX_NAME>',
['operation' => 'move',
'destination' => '<DESTINATION_INDEX_NAME>',
'scope' => [
'rules',
'settings',
],
],
);
// play with the response
var_dump($response);
$client->waitForTask('<SOURCE_INDEX_NAME>', $response['taskID']);
from algoliasearch.search.client import SearchClient
_client = SearchClient("YOUR_APP_ID", "YOUR_API_KEY")
response = await _client.operation_index(
index_name="<SOURCE_INDEX_NAME>",
operation_index_params={
"operation": "move",
"destination": "<DESTINATION_INDEX_NAME>",
"scope": [
"rules",
"settings",
],
},
)
# use the class directly
print(response)
# print the JSON response
print(response.to_json())
await client.wait_for_task(index_name="<SOURCE_INDEX_NAME>", task_id=response.task_id)
require 'algolia'
client = Algolia::SearchClient.create('YOUR_APP_ID', 'YOUR_API_KEY')
response = client.operation_index(
"<SOURCE_INDEX_NAME>",
OperationIndexParams.new(
operation: 'move',
destination: "<DESTINATION_INDEX_NAME>",
scope: ['rules', 'settings']
)
)
# use the class directly
puts response
# print the JSON response
puts response.to_json
client.wait_for_task("<SOURCE_INDEX_NAME>", response.task_id)
import algoliasearch.api.SearchClient
val client = SearchClient(appId = "YOUR_APP_ID", apiKey = "YOUR_API_KEY")
val response = client.operationIndex(
indexName = "<SOURCE_INDEX_NAME>",
operationIndexParams = OperationIndexParams(
operation = OperationType.withName("move"),
destination = "<DESTINATION_INDEX_NAME>",
scope = Some(Seq(ScopeType.withName("rules"), ScopeType.withName("settings")))
)
)
// Use the response
val value = Await.result(response, Duration(100, "sec"))
client.waitTask("<SOURCE_INDEX_NAME>", response.getTaskID())
import Search
let client = try SearchClient(appID: "YOUR_APP_ID", apiKey: "YOUR_API_KEY")
let response = try await client.operationIndex(
indexName: "<SOURCE_INDEX_NAME>",
operationIndexParams: OperationIndexParams(
operation: OperationType.move,
destination: "<DESTINATION_INDEX_NAME>",
scope: [ScopeType.rules, ScopeType.settings]
)
)
try await client.waitForTask(with: response.taskID, in: "<SOURCE_INDEX_NAME>")
saveObjects
The saveObjects
method has been removed, you can leverage the already existing batch
method instead.
Read more in our dedicated guide or the API reference.
- C#
- Dart
- Go
- Java
- JavaScript
- Kotlin
- PHP
- Python
- Ruby
- Scala
- Swift
using Algolia.Search.Clients;
using Algolia.Search.Http;
var client = new SearchClient(new SearchConfig("YOUR_APP_ID", "YOUR_API_KEY"));
var response = await client.BatchAsync(
"<YOUR_INDEX_NAME>",
new BatchWriteParams
{
Requests = new List<BatchRequest>
{
new BatchRequest
{
Action = Enum.Parse<Action>("AddObject"),
Body = new Dictionary<string, string> { { "key", "bar" }, { "foo", "1" } },
},
new BatchRequest
{
Action = Enum.Parse<Action>("AddObject"),
Body = new Dictionary<string, string> { { "key", "baz" }, { "foo", "2" } },
}
},
}
);
await client.WaitForTaskAsync("<YOUR_INDEX_NAME>", response.TaskID);
import 'package:algolia_client_search/algolia_client_search.dart';
final client = SearchClient(appId: 'YOUR_APP_ID', apiKey: 'YOUR_API_KEY');
final response = await client.batch(
indexName: "<YOUR_INDEX_NAME>",
batchWriteParams: BatchWriteParams(
requests: [
BatchRequest(
action: Action.fromJson("addObject"),
body: {
'key': "bar",
'foo': "1",
},
),
BatchRequest(
action: Action.fromJson("addObject"),
body: {
'key': "baz",
'foo': "2",
},
),
],
),
);
await client.waitTask('<YOUR_INDEX_NAME>', response.taskID);
import "github.com/algolia/algoliasearch-client-go/v4/algolia/search"
client, err := search.NewClient("YOUR_APP_ID", "YOUR_API_KEY")
response, err := client.Batch(client.NewApiBatchRequest(
"<YOUR_INDEX_NAME>",
search.NewEmptyBatchWriteParams().SetRequests(
[]search.BatchRequest{*search.NewEmptyBatchRequest().SetAction(search.Action("addObject")).SetBody(map[string]any{"key": "bar", "foo": "1"}), *search.NewEmptyBatchRequest().SetAction(search.Action("addObject")).SetBody(map[string]any{"key": "baz", "foo": "2"})}),
))
if err != nil {
// handle the eventual error
panic(err)
}
// use the model directly
print(response)
taskResponse, err := searchClient.WaitForTask("<YOUR_INDEX_NAME>", response.TaskID, nil, nil, nil)
if err != nil {
panic(err)
}
import com.algolia.api.SearchClient;
import com.algolia.model.search.*;
SearchClient client = new SearchClient("YOUR_APP_ID", "YOUR_API_KEY");
client.batch(
"<YOUR_INDEX_NAME>",
new BatchWriteParams()
.setRequests(
List.of(
new BatchRequest().setAction(Action.ADD_OBJECT).setBody(Map.of("key", "bar", "foo", "1")),
new BatchRequest().setAction(Action.ADD_OBJECT).setBody(Map.of("key", "baz", "foo", "2"))
)
)
);
client.waitForTask("<YOUR_INDEX_NAME>", response.getTaskID());
import { searchClient } from '@algolia/client-search';
const client = searchClient('YOUR_APP_ID', 'YOUR_API_KEY');
const response = await client.batch({
indexName: '<YOUR_INDEX_NAME>',
batchWriteParams: {
requests: [
{ action: 'addObject', body: { key: 'bar', foo: '1' } },
{ action: 'addObject', body: { key: 'baz', foo: '2' } },
],
},
});
// use typed response
console.log(response);
await client.waitForTask({ indexName: '<YOUR_INDEX_NAME>', taskID: response.taskID });
import com.algolia.client.api.SearchClient
val client = SearchClient(appId = "YOUR_APP_ID", apiKey = "YOUR_API_KEY")
var response = client.batch(
indexName = "<YOUR_INDEX_NAME>",
batchWriteParams = BatchWriteParams(
requests = listOf(
BatchRequest(
action = Action.entries.first { it.value == "addObject" },
body = buildJsonObject {
put(
"key",
JsonPrimitive("bar"),
)
put(
"foo",
JsonPrimitive("1"),
)
},
),
BatchRequest(
action = Action.entries.first { it.value == "addObject" },
body = buildJsonObject {
put(
"key",
JsonPrimitive("baz"),
)
put(
"foo",
JsonPrimitive("2"),
)
},
),
),
),
)
// Use the response
println(response)
client.waitTask("<YOUR_INDEX_NAME>", response.taskID)
use Algolia\AlgoliaSearch\Api\SearchClient;
$client = SearchClient::create('<YOUR_APP_ID>', '<YOUR_API_KEY>');
$response = $client->batch(
'<YOUR_INDEX_NAME>',
['requests' => [
['action' => 'addObject',
'body' => ['key' => 'bar',
'foo' => '1',
],
],
['action' => 'addObject',
'body' => ['key' => 'baz',
'foo' => '2',
],
],
],
],
);
// play with the response
var_dump($response);
$client->waitForTask('<YOUR_INDEX_NAME>', $response['taskID']);
from algoliasearch.search.client import SearchClient
_client = SearchClient("YOUR_APP_ID", "YOUR_API_KEY")
response = await _client.batch(
index_name="<YOUR_INDEX_NAME>",
batch_write_params={
"requests": [
{
"action": "addObject",
"body": {
"key": "bar",
"foo": "1",
},
},
{
"action": "addObject",
"body": {
"key": "baz",
"foo": "2",
},
},
],
},
)
# use the class directly
print(response)
# print the JSON response
print(response.to_json())
await client.wait_for_task(index_name="<YOUR_INDEX_NAME>", task_id=response.task_id)
require 'algolia'
client = Algolia::SearchClient.create('YOUR_APP_ID', 'YOUR_API_KEY')
response = client.batch(
"<YOUR_INDEX_NAME>",
BatchWriteParams.new(
requests: [
BatchRequest.new(
action: 'addObject',
body: { key: "bar",
foo: "1" }
),
BatchRequest.new(action: 'addObject', body: { key: "baz", foo: "2" })
]
)
)
# use the class directly
puts response
# print the JSON response
puts response.to_json
client.wait_for_task("<YOUR_INDEX_NAME>", response.task_id)
import algoliasearch.api.SearchClient
val client = SearchClient(appId = "YOUR_APP_ID", apiKey = "YOUR_API_KEY")
val response = client.batch(
indexName = "<YOUR_INDEX_NAME>",
batchWriteParams = BatchWriteParams(
requests = Seq(
BatchRequest(
action = Action.withName("addObject"),
body = JObject(List(JField("key", JString("bar")), JField("foo", JString("1"))))
),
BatchRequest(
action = Action.withName("addObject"),
body = JObject(List(JField("key", JString("baz")), JField("foo", JString("2"))))
)
)
)
)
// Use the response
val value = Await.result(response, Duration(100, "sec"))
client.waitTask("<YOUR_INDEX_NAME>", response.getTaskID())
import Search
let client = try SearchClient(appID: "YOUR_APP_ID", apiKey: "YOUR_API_KEY")
let response = try await client.batch(
indexName: "<YOUR_INDEX_NAME>",
batchWriteParams: BatchWriteParams(requests: [
BatchRequest(action: Action.addObject, body: ["key": "bar", "foo": "1"]),
BatchRequest(action: Action.addObject, body: ["key": "baz", "foo": "2"]),
])
)
try await client.waitForTask(with: response.taskID, in: "<YOUR_INDEX_NAME>")
browseObjects
/browseRules
/browseSynonyms
The browseObjects
/browseRules
/browseSynonyms
signature have changed to match the general usage of the API clients.
- C#
- Dart
- Go
- Java
- JavaScript
- Kotlin
- PHP
- Python
- Ruby
- Scala
- Swift
// browse records
const records: Record<string, any> = [];
await client.browseObjects({
// all base `browse` options are forwarded to the `browse` method
indexName: '<YOUR_INDEX_NAME>',
// the aggregator to execute right after the API call has been resolved
aggregator: (response) => records.push(...response.hits),
});
console.log(records, records.length);
// browse rules
const rules: Record<string, any> = [];
await client.browseRules({
// all base `searchRules` options are forwarded to the `searchRules` method
indexName: '<YOUR_INDEX_NAME>',
// the aggregator to execute right after the API call has been resolved
aggregator: (response) => rules.push(...response.hits),
});
console.log(rules, rules.length);
// browse synonyms
const synonyms: Record<string, any> = [];
await client.browseSynonyms({
// all base `searchSynonyms` options are forwarded to the `searchSynonyms` method
indexName: '<YOUR_INDEX_NAME>',
// the aggregator to execute right after the API call has been resolved
aggregator: (response) => synonyms.push(...response.hits),
});
console.log(synonyms, synonyms.length);
# browse records
responses = []
await client.browse_objects(
# all base `browse` options are forwarded to the `browse` method
index_name="<YOUR_INDEX_NAME>"
aggregator=lambda _resp, responses.append(_resp)
)
print(responses)
# browse rules
rules = []
await client.browse_rules(
# all base `search_rules` options are forwarded to the `search_rules` method
index_name="<YOUR_INDEX_NAME>"
aggregator=lambda _resp, rules.append(_resp)
)
print(rules)
# browse synonyms
synonyms = []
await client.browse_synonyms(
# all base `search_synonyms` options are forwarded to the `search_synonyms` method
index_name="<YOUR_INDEX_NAME>"
aggregator=lambda _resp, synonyms.append(_resp)
)
print(synonyms)
// browse records
$results = $client->browseObjects($indexName);
$objects = [];
foreach ($results as $object) {
$objects[] = $object;
}
var_dump($objects);
// browse synonyms
$results = $client->browseSynonyms($indexName);
$synonyms = [];
foreach ($results as $synonym) {
$synonyms[] = $synonym;
}
var_dump($synonyms);
// browse rules
$results = $client->browseRules($indexName);
$rules = [];
foreach ($results as $rule) {
$rules[] = $rule;
}
var_dump($rules);
// browse records
Iterable<MyObject> objects = client.browseObjects(
"<YOUR_INDEX_NAME>",
// all base `browse` options are forwarded to the `browse` method
new BrowseParamsObject()
);
for (MyObject object : objects) {
System.out.println(object.myProperty);
}
// browse rules
Iterable<Rule> rules = client.browseRules(
"<YOUR_INDEX_NAME>",
// all base `searchRules` options are forwarded to the `searchRules` method (optional)
new SearchRulesParams()
);
for (Rule rule : rules) {
System.out.println(rule);
}
// browse synonyms
Iterable<SynonymHit> synonyms = client.browseRules(
"<YOUR_INDEX_NAME>",
// only search for specific types of synonyms. (optional)
null,
// all base `searchSynonyms` options are forwarded to the `searchSynonyms` method (optional)
new SearchSynonymsParams()
);
for (SynonymHit synonym : synonyms) {
System.out.println(synonym);
}
using Algolia.Search.Clients;
using Algolia.Search.Models.Search;
using Algolia.Search.Utils;
var client = new SearchClient("<YOUR_APP_ID>", "<YOUR_API_KEY>");
var browseObjects = await client.BrowseObjectsAsync<Actor>("<YOUR_INDEX_NAME>",
// all base `browse` options are forwarded to the `browse` method
new BrowseParamsObject());
foreach (var actor in browseObjects)
{
Console.WriteLine(actor.Name);
}
var browseRules = await client.BrowseRulesAsync("<YOUR_INDEX_NAME>",
// all base `searchRules` options are forwarded to the `searchRules` method (optional)
new SearchRulesParams());
foreach (var rule in browseRules)
{
Console.WriteLine(rule);
}
var browseSynonyms = await client.BrowseSynonymsAsync("<YOUR_INDEX_NAME>",
// all base `searchSynonyms` options are forwarded to the `searchSynonyms` method (optional)
new SearchSynonymsParams());
foreach (var synonym in browseSynonyms)
{
Console.WriteLine(synonym);
}
Client’s specific breaking changes
You can find specific client breaking changes in their own section: