Sep 20, 2024
Create or replace synonyms
If a synonym with the objectID
doesn’t exist, Algolia adds a new one.
Otherwise, existing synonyms are replaced.
Usage
Required ACL:
editSettings
Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import com.algolia.client.api.SearchClient
import com.algolia.client.extensions.*
val client = SearchClient(appId = "ALGOLIA_APPLICATION_ID", apiKey = "ALGOLIA_API_KEY")
var response = client.saveSynonyms(
indexName = "ALGOLIA_INDEX_NAME",
synonymHit = listOf(
SynonymHit(
objectID = "id1",
type = SynonymType.entries.first { it.value == "synonym" },
synonyms = listOf("car", "vehicule", "auto"),
),
SynonymHit(
objectID = "id2",
type = SynonymType.entries.first { it.value == "onewaysynonym" },
input = "iphone",
synonyms = listOf("ephone", "aphone", "yphone"),
),
),
forwardToReplicas = true,
replaceExistingSynonyms = true,
)
Did you find this page helpful?