Skip to main content
Use compositions to define sorting strategies and apply them at runtime. With sorting strategies, you can sort at query time based on price, recency, popularity, or custom business logic from your Algolia indices.

Define sorting strategies with the API

To configure sorting behavior programmatically, use the Composition API. The following explains how to set and apply sorting strategies.

Set sorting strategies in a composition

You can use the Composition API to configure the sorting strategy programmatically. The sorting strategies are defined in the sortingStrategy parameter (available at root level):
JSON
sortingStrategy is an object where:
  • Key is the sorting label your UI will send at run time (for example Price (asc))
  • Value is the Algolia index or replica to use when this sorting is selected (for example Products-sorted-by-price-low-to-high)

Select a sorting strategy at runtime

When querying your composition, you can select the sorting strategy to apply to Smart Group results by sending the sortBy parameter with your .
JSON
  • The value sent with sortBy must match one of the keys defined in the composition’s sortingStrategy map. If no match is found, sortBy is ignored.
  • The order of items defined in the Smart Group remains fixed. Only the are affected by sortBy.
  • If a composition rule applies to the query, it’s applied first. Then, the sorting strategy affects the defined by that rule.
This ensures predictable behavior, especially when Smart Groups include mixed sources.

Sort multifeed compositions

In a multifeed composition, you can apply sortBy to the whole composition or to individual feeds:
  • Per composition: send sortBy in the root params. Feeds inherit it unless they set their own sortBy.
  • Per feed: send sortBy in feeds.<feedID>.params. The feed value replaces the root value.
JSON
  • To turn sorting off for a feed that would otherwise inherit the root sortBy, set "sortBy": "" in the feed’s params.
  • When the composition runs, the API ignores a sorting index that’s unrelated to the feed’s indices and reports it in the errors property. The API also ignores invalid sortBy values and reports them in the errors property.
  • Rules that trigger on sortBy match only the root value. A sortBy value set only for a feed doesn’t trigger rules.
For more information, see Set parameters per feed.

Integrate with InstantSearch

Composition sorting strategies require these versions of the InstantSearch libraries:
  • React InstantSearch: version 7.22.1 or later
  • InstantSearch.js: version 4.86.1 or later
  • Vue InstantSearch: version 4.22.8 or later
For more information, see Integrate compositions with InstantSearch.
To apply the sorting strategies, use the sortBy widget with strategy instead of value on the items option.
JavaScript
Last modified on November 6, 2026