Guides / Managing results / Refine results / Sorting results

It’s common to have several replica indices that differ from their primary index by a single setting, such as the sorting strategy. Products in an ecommerce store are a good example. You may have a primary index sorted by ascending price, and one or more replicas that sort products by descending price, descending popularity, descending rating, etc.

Despite these different sorting settings, you may still want to copy settings from one index to its replicas or other indices. For example, if you decide to change the searchableAttributes setting, you probably want it to apply to all indices.

The forwardToReplicas parameter allows you to forward new settings to replicas. From there, you can change only the settings that need to be different and keep all others synchronized.

Example of multiple indices

You have a primary index called products and a products_price_desc replica. Both indices have the same data and settings, apart from the ranking setting.

If you want to change the searchableAttributes setting to include a new description attribute for all indices, primary and replicas, use the forwardToReplicas parameter.

Using the API

The setSettings method, along with all synonyms and Rules methods, have a forwardToReplicas parameter. By default, forwardToReplicas is false, so any setting, synonym, or Rule change only applies to the target index. By setting it to true, you can forward these changes to all the replicas belonging to the index you target.

1
2
3
4
5
6
7
8
$forwardToReplicas = true;

$index->setSettings(
  [
    'searchableAttributes' => ['name', 'description'],
  ],
  $forwardToReplicas
);

Settings are only forwarded to existing replicas. If you want to forward settings and create a replica, you first have to create the replica and forward the settings after. These must be separate operations.

Using the dashboard

Whenever you make settings changes, Algolia’s dashboard will prompt you to review them before saving and gives you the option to Copy these settings to other indices and/or replicas.

Whenever you copy settings changes to indices, you replace the previous setting on the index. For example, if you change the ranking formula on the primary index to include a sort on an inventory attribute, and then choose to copy the updated ranking setting to all replicas, you overwrite any previously set sorts on other attributes on the replicas.

When altering the ranking formula on indices with replicas, you are recommended to do it on a per index basis.

While customRanking is part of the ranking formula, it’s a setting as well. You can alter the custom ranking and forward the change to your replicas without worrying about overwriting the entire ranking formula.

You usually don’t need to worry about overwriting settings, since you typically want most settings to be the same between replicas. Notable exceptions include ranking and typoTolerance.

Copy synonyms and Rules

The dashboard also allows you to batch import and export synonyms and Rules with a configuration file.

Did you find this page helpful?