Concepts / Managing results / Understanding Replicas
Jul. 17, 2019

Understanding Replicas

By design, Algolia provides one ranking formula per index. Every index has a unique sorting strategy, which is statically defined at the index level, and cannot be changed at query time. Pre-sorting at index time instead of at query time leads to a considerable performance boost.

When you want to provide different rankings for the same data, you need to use replica indices.

Algolia provides primary/replica relationships to let you automatically replicate the content of one index (the primary) onto other indices (the replicas) and synchronize content changes.

What’s in a replica?

Replicas are linked to their primary index: a replica copies a primary index’s content, but can have different settings.

Data

Replicas have the exact same data as their primary index, and data synchronization is done automatically for you. Every time you add, update, or delete records in your primary index, your replica is simultaneously modified. You cannot alter this automatic data synchronization.

For example, you cannot directly add, update, or delete records in your replica indices.

Settings

Replicas start with the exact same settings as their primary index. However, you can change a replica’s settings.

Typically, you’ll want to keep most settings in sync with your primary index. You can ensure setting synchronization by forwarding settings changes made to your primary index to its replicas: to achieve this, set the forwardToReplica parameter to true when using the setSettings method.

The most common modifications to a replica’s settings are to its sorting strategy.

Creating replicas

Multiple ranking formulas are useful to implement different sorting strategies (e.g., sort by price, ascending or descending, sort by most viewed, etc.)

You can create replicas with the dashboard, or you can use the replicas setting when using the API. Whichever method you choose, these actions replicate all data and settings. You then need to change the sorting strategy of the replica.

Querying replicas

When you want to search a replica index, you need to target the replica index as you would with any primary index.

Changing a replica’s settings

Concerning settings, a replica is like any other index: You can change any of its settings. This can be done for many reasons, one of the most common is when doing A/B testing.

Deleting or detaching a replica

You cannot edit the contents of a replica index. If you want to edit or delete the replica, you first have to unlink it from its primary index, which turns it into a regular index. Once done, changes to the primary index no longer propagate to the replica index.

Did you find this page helpful?