Keep your Scala API client up to date to benefit from improvements and bug fixes.
The latest major version of the algoliasearch-scala package is version 2.
This page helps you upgrade from version 1
and explains the breaking changes you need to address.Algolia generates the version 2 client from OpenAPI specifications,
which provides consistent behavior across all languages and up-to-date API coverage.
The main architectural change is the removal of the domain-specific language (DSL).
Instead of writing expressions like client.execute { search into "index" query "q" } (version 1), you call methods directly on the SearchClient instance, passing named parameters.For the full list of changes, see the Scala changelog.
Update the algoliasearch-scala package to version 2.With sbt, update the version range in your build.sbt file:
build.sbt
// version 1libraryDependencies += "com.algolia" %% "algoliasearch-scala" % "[1,)"// version 2libraryDependencies += "com.algolia" %% "algoliasearch-client-scala" % "[2,)"
With Maven, update the version in your pom.xml file:
pom.xml
<!-- version 1 --><dependency> <groupId>com.algolia</groupId> <artifactId>algoliasearch-scala_2.13</artifactId> <version>[1,)</version></dependency><!-- version 2 --><dependency> <groupId>com.algolia</groupId> <artifactId>algoliasearch-client-scala_2.13</artifactId> <version>[2,)</version></dependency>
The version 2 client is cross-published for Scala 2.13 and Scala 3.
sbt resolves the correct artifact automatically based on your scalaVersion.
If you use Maven, replace _2.13 with _3 in the artifactId for Scala 3 projects.
The client class was renamed from AlgoliaClient to SearchClient,
and you no longer use the new keyword.
Scala
// version 1val client = new AlgoliaClient("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY")// version 2val client = SearchClient(appId = "ALGOLIA_APPLICATION_ID", apiKey = "ALGOLIA_API_KEY")
Unlike other language clients, version 1 of the Scala client didn’t have a separate initIndex step.
The DSL handled index references inline, embedding the index name into expressions like search into "index".
In version 2, you pass indexName as a named parameter to every method. There’s no index object and no DSL expression.
This is the most significant change when upgrading the Scala client.
Version 1 provided a domain-specific language (DSL) through algolia.AlgoliaDsl._
that let you write expressive, English-like code inside client.execute { ... } blocks.
Version 2 removes the DSL entirely.Every client.execute { ... } call must be replaced with a direct method call on the client.
Here are the most common DSL patterns and their replacements:
// version 1 (case class deserialization via json4s)val future: Future[Seq[Contact]] = client .execute { search into "index" query "a" } .map { search => search.as[Contact] }// version 2// The response contains raw JSON. Parse with json4s or your preferred library.val response: Future[SearchResponse] = client.searchSingleIndex( indexName = "INDEX_NAME", searchParams = Some( SearchParamsObject(query = Some("a")) ) )
Search your codebase for client.execute, AlgoliaDsl, and import algolia. to find every place that needs changing.
Many synonym and rule operations weren’t available in version 1 of the Scala client.
Version 2 includes full coverage of the API, including saveSynonyms, saveRules, and replaceAllObjects.
In version 1, replaceAllRules and replaceAllSynonyms weren’t available in the Scala client.
In version 2, use client.saveRules() with clearExistingRules = Some(true) or client.saveSynonyms() with replaceExistingSynonyms = Some(true) to replace all rules or synonyms.
Version 1 relied on calling .wait() on Future results or Await.ready.
Version 2 replaces this pattern with dedicated wait helpers.
Since all methods return Future[...], you can chain waitForTask with a flatMap:
Scala
// version 1val indexing = client.execute { index into "INDEX_NAME" `object` Record("test", "1")}Await.ready(indexing, Duration.Inf)// version 2val result: Future[SaveObjectResponse] = client.saveObject( indexName = "INDEX_NAME", body = JObject(List(JField("objectID", JString("1")), JField("name", JString("test")))) )val waited: Future[GetTaskResponse] = result.flatMap { r => client.waitForTask( indexName = "INDEX_NAME", taskID = r.taskID ) }
Version 2 includes three wait helpers:
waitForTask: wait until indexing operations are done.
New in version 2. Atomically replaces all objects in an index by copying it, batch-saving new objects, then moving the copy back. batchSize defaults to 1,000 and scopes defaults to ["settings", "rules", "synonyms"].
New in version 2. Polls until an API key operation (add, update, or delete) has propagated.
Scala
// Wait for a key to be created:client.waitForApiKey(key = "my-api-key", operation = ApiKeyOperation.Add)// Wait for a key update (pass the expected final state):client.waitForApiKey( key = "my-api-key", operation = ApiKeyOperation.Update, apiKey = Some(ApiKey(acl = Seq(Acl.Search))))
There is no built-in cross-application copy helper in the Scala client, but you can compose existing helpers across two clients to achieve the same result.