Concepts / Sending and managing data / Different Synchronization Strategies
Feb. 18, 2019

Different Synchronization Strategies

Overview

At this point, you’ve already created your index, and it’s working fine. If you haven’t, you need to do an initial push of your data.

There are several ways to update your index:

  1. Reindexing: replace your entire index with a new set of records
  2. Full record update: replace an entire record
  3. Partial record updates: change only some attributes

Reindexing

Most of the time, you need to reindex in the following scenarios:

  • You’ve changed your index’s structure
  • Your source has significantly changed since the last update
  • You need to resolve “data drift”, which happens when you have many different sources of data, making it difficult to track changes effectively

Full Record Updates

The saveObjects method is designed for replacing entire records. You need the correct objectID of the record you wish to replace, and all of its attributes.

When using saveObjects, if you omit any attribute, it won’t be in the index.

Partial Record Updates

The partialUpdateObjects method is designed to replace individual attributes in records. You need the correct objectID of the record whose attributes you wish to change, and a subset of attributes you wish to change.

Any attribute you specify in partialUpdateObjects will appear in your records. If the attribute already exists, its content will be updated. If it doesn’t, it will be created. Unlike with saveObjects, any attribute that’s in the record and that you don’t specify in partialUpdateObjects will remain untouched.

Differences Between Add, Update, and Partial Updates

Algolia offers three methods to change the content of your index. It’s important to understand their differences so you can better manage your updates.

Add objects

You need to use addObjects when you want to add new records to your index.

That said, you can also use this method to update records, by including the objectID of an existing record. We don’t recommend doing this. Instead, you should use saveObjects.

The addObjects method doesn’t require an objectID.

  • When you specify an objectID and the objectID doesn’t exist in the index, a new record is created.
  • When you specify an objectID and the objectID already exists in the index, the related record is replaced.
  • When you don’t specify an objectID, Algolia automatically assigns an objectID, which is returned in the response.

Update objects

You need to use saveObjects when you want to replace an entire record.

The saveObjects method requires an objectID.

  • When the specified objectID exists in the index, the related record is replaced.
  • When the specified objectID doesn’t exist in the index, a new record is created.
  • When the objectID isn’t specified, the method returns an error.

Note: The method used to update an object is called saveObjects. Throughout the documentation, we use these terms interchangeably.

Partial update objects

You need to use partialUpdateObjects when you want to replace individual attributes.

The partialUpdateObjects method requires an objectID.

  • When the specified objectID exists in the index, the attributes are replaced.
  • When the specified objectID doesn’t exist in the index, a new record is created.
  • When the objectID isn’t specified, the method returns an error.

Note: One important thing to keep in mind is that the partialUpdateObjects method doesn’t replace the whole object. It only adds, removes, or updates specified individual attributes. Unspecified attributes are left untouched. This is different from addObjects and saveObjects, both of which replace the whole object.

For all three

  • Each of these methods has singular and plural forms.
    • If singular (e.g., addObject), the method only accepts a single object as an argument
    • If plural (e.g., addObjects), the method accepts one or many objects

Did you find this page helpful?