#community-help

Updating Array Field in Typesense Integration

TLDR Krish queried about updating array field on Typesense. Kishore Nallan explained how to do this, but noted that the array must be replaced instead of appended to.

Powered by Struct AI
Dec 13, 2022 (12 months ago)
Krish
Photo of md5-7dff5651efcba5c9cdfac93918dc7eeb
Krish
03:01 PM
Hey ! I am new here and trying to integrate type sense to my app. I have a basic question; can I update a field of type array in a document such that I add a new value to it?
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
03:08 PM
You can send partial updates to Typesense which can contain one more field values that are changed (this includes a value added to an array). Typesense will then update the index with those changes.
03:11
Kishore Nallan
03:11 PM
Also can be done in bulk via the import end-point. See the action modes possible: https://typesense.org/docs/0.23.1/api/documents.html#action-modes-batch-create-upsert-update-emplace
Krish
Photo of md5-7dff5651efcba5c9cdfac93918dc7eeb
Krish
03:15 PM
thank you, let me try
03:24
Krish
03:24 PM
So, if the field is an array would the update(id) automatically append the value to the field?
03:26
Krish
03:26 PM
Also, will an upsert append data to the existing array if it already exists
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
04:08 PM
No we don't have an append operation.. you've to send the whole array with the appended field.
Dec 14, 2022 (12 months ago)
Krish
Photo of md5-7dff5651efcba5c9cdfac93918dc7eeb
Krish
05:11 AM
OK, thank you!