Track each record with a unique identifier
To perform incremental updates, you need to declare a unique identifier for each record so you can track what data matches what record. This identifier should map to a “key” you store on your side. You need to store the unique identifier in theobjectID attribute.
Add records
Whenever you add new data in your data source, you can add them to Algolia with thesaveObjects method.
Update records
You can update records in two ways:- Fully replace the old record with a new one
- Update only a subset of the record (attributes) with new data
Replace old records
When saving a record in Algolia, if a record with the specifiedobjectID already exists in the index,
the engine replaces it.
You can replace an existing record by using the saveObjects method and specifying the objectID.
This technique is useful when you’re updating data in a single place in your system, or when you don’t know what changed.
Update a subset of the record
When you don’t need to replace the entire record, you can also update specific attributes of a record. This is useful when you know which attribute to update, but you don’t know the other attributes, for example, when different systems manage different aspects of your data. For this, you can use thepartialUpdateObjects method and only pass the changed data.
Anything you don’t specify remains untouched.
Delete records
Whenever you delete data in your data source, you can delete the corresponding record from Algolia withdeleteObjects.
Delete by query
Sometimes, you may need to delete all records matching a certain filter. Back to the book example, if you stop selling books from a specific publisher, you might want to delete all records matching thispublisher in your index. To do this, you can use the deleteBy method.
The
deleteBy method is an expensive operation for the engine.
For better performance, use the deleteObjects method instead.Any attribute you’re using to delete by needs to be in your
searchableAttributes.