Create or replace synonyms

If a synonym with the objectID doesn’t exist, Algolia adds a new one. Otherwise, existing synonyms are replaced.

This operation is subject to indexing rate limits.

Usage

Required ACL: editSettings
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import algoliasearch.api.SearchClient
import algoliasearch.extension.SearchClientExtensions

val client = SearchClient(appId = "ALGOLIA_APPLICATION_ID", apiKey = "ALGOLIA_API_KEY")

val response = client.saveSynonyms(
  indexName = "ALGOLIA_INDEX_NAME",
  synonymHit = Seq(
    SynonymHit(
      objectID = "id1",
      `type` = SynonymType.withName("synonym"),
      synonyms = Some(Seq("car", "vehicule", "auto"))
    ),
    SynonymHit(
      objectID = "id2",
      `type` = SynonymType.withName("onewaysynonym"),
      input = Some("iphone"),
      synonyms = Some(Seq("ephone", "aphone", "yphone"))
    )
  ),
  forwardToReplicas = Some(true),
  replaceExistingSynonyms = Some(true)
)
Did you find this page helpful?
Scala API clients v2