Guides / Managing results / Refine results / Sorting results

Algolia has one ranking formula per index. Every index has a unique sorting strategy but you can’t change it at query time. This is because pre-sorting during indexing instead of at query time leads to a considerable performance boost.

The key use of replica indices is they let you provide different rankings for the same data.

Algolia lets you automatically replicate the content of one index (the primary) onto other indices (standard and virtual replicas) and synchronize content changes.

Standard and virtual replicas

Standard or virtual replicas are optimized for different use cases:

  • Exhaustive sorting. Use standard replicas if you want to show everything that matches, strictly sorted by a chosen attribute. For example, on a news site sort articles by publication date.

  • Relevant sorting. Use virtual replicas to prioritize relevant results while still incorporating the sorting preference for the selected attribute. For example, searching for “notebook” should show laptops first, not notebook accessories.

    This feature isn’t available on every plan. Refer to your pricing plan to see if it’s included.

Similarities

  • You can search a replica index as you would any primary index.
  • You can’t add, update, or delete records in replica indices.
  • Both replica types synchronize with any updates made to records in the primary index. Every time you add, update, or delete records in your primary index, your replica is automatically modified. You can’t alter this automatic data synchronization.

Index settings

Replicas start with the same settings as their primary index, but you can change them. For example, to sort:

  • By price
  • In ascending order
  • In descending order
  • By most viewed.

Algolia applies one sorting strategy to each index.

You can only sort by attributes with boolean or numerical values. If you want to sort by dates, convert the dates to Unix timestamps.

To keep replica settings in sync with your primary index, set the primary index’s forwardToReplicas parameter to true with the setSettings method.

Differences

  Standard replicas Virtual replicas
Records Increases the number of records since it’s a copy of its primary index Doesn’t increase the number of records since it’s just a view of its primary index. It does slightly increase the primary index’s size (but by less than 10 MB per million records)
Usage Optimized for exhaustive sorting Optimized for relevant sorting
Number of replicas per index Unlimited 20
Supported index settings All A subset
Synonyms Supports all synonym types Supports most synonym types, except placeholders
API response that returns the number of hits nbHits nbSortedHits
Optional filters Applied after a sort-by attribute. Can’t be used to boost or bury records. Incompatible with virtual replicas

Manage replicas

For more details about creating and deleting replica indices, see:

Supported index settings for virtual replicas

Virtual replicas support a subset of the index settings.

Supported settings

Unsupported settings

You can’t change the following parameters for virtual indices. Instead, change them on the corresponding primary index or create a standard replica.

Did you find this page helpful?