Sep 20, 2024
Add a new record (with auto-generated object ID)
Adds a record to an index or replaces it.
- If the record doesn’t have an object ID, a new record with an auto-generated object ID is added to your index.
- If a record with the specified object ID exists, the existing record is replaced.
- If a record with the specified object ID doesn’t exist, a new record is added to your index.
- If you add a record to an index that doesn’t exist yet, a new index is created.
To update some attributes of a record, use the partial
operation.
To add, update, or replace multiple records, use the batch
operation.
This operation is subject to indexing rate limits.
Usage
Required ACL:
addObject
Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import com.algolia.client.api.SearchClient
import com.algolia.client.configuration.*
import com.algolia.client.transport.*
import com.algolia.client.extensions.*
val client = SearchClient(appId = "ALGOLIA_APPLICATION_ID", apiKey = "ALGOLIA_API_KEY")
var response = client.saveObject(
indexName = "ALGOLIA_INDEX_NAME",
body = buildJsonObject {
put(
"name",
JsonPrimitive("Black T-shirt"),
)
put(
"color",
JsonPrimitive("#000000||black"),
)
put(
"availableIn",
JsonPrimitive("https://source.unsplash.com/100x100/?paris||Paris"),
)
put(
"objectID",
JsonPrimitive("myID"),
)
},
)
Did you find this page helpful?