Choosing Between One or More Indices
On this page
Algolia lets you put all your records into a single index, or spread them across several indices. By default, you can create up to 1,000 indices.
Multiple indices are appropriate when you have different kinds of data to index, such as movies, actors, etc. They’re also useful to provide different ranking strategies for the same data, such as most recent movies or highest rated movies. Regardless, how you organize your indices corresponds to how you want to search and display your records.
Imagine a website that has a search experience for movies, and another one for actors. When searching for a movie, you may want to retrieve the cast. When searching for a specific actor, you may want to retrieve a list of the movies in which they performed. Although the experience is seamless for the end user, they’re still searching for two different types of data. In this case, you’re better off with separate indices. Using separate indices lets you configure each index independently, and tailor them to their specific content.
Conversely, you might want to create a single, unified experience. Users may want to search for anything, see movies and actors in the same results, and rank them together. In this case, a single index would be a better fit.
There are other use cases for using several indices. For example, if you want to present popular queries with an autocomplete menu, you could leverage the Query Suggestions feature. In this case, you need two indices: one for your content, and one for the common queries.
Different sorting strategies
You also need to use separate indices when you want to let your users switch between different rankings. For example, with a search experience displaying products, you may want to allow users to sort by ascending or descending price. You can’t dynamically change the ranking of an Algolia index, but you can use replica indices. A replica is a special index holding the same data, with different ranking strategy.
Replicas are ideal for providing different sorting options. All you need to do is offer a way for your end users to select a sorting option on your front end and dynamically switch to the right index.
It’s best to use separate indices for all your environments and generate new indices and API keys for each of them. This lets you not skew your search analytics, avoids indexing accidents, and keeping each environment more secure.
For example, if you have three environments, such as development, staging, and production, you can create three indices:
prod_products. To reduce the impact of testing and staging on your operation count, you can use a subset of your data in non-production environments. For example, you can test your staging environment with 10% of your records.