This is the React InstantSearch v7 documentation.
If you’re upgrading from v6, see the upgrade guide.
If you were using React InstantSearch Hooks,
this v7 documentation applies—just check for necessary changes.
To continue using v6, you can find the archived documentation.
Search multiple indices with InstantSearch
You can search several Algolia indices at once in your React InstantSearch app using multipleIndex
widgets. All indices must be on the same Algolia application.
React
Root-level and nested widgets
You can add any available widget in anIndex
. Nested widgets only affect this particular index, while direct children of the root InstantSearch
widget impact everything.
In the following example, when typing in SearchBox
, the query applies to both indices. Conversely, each Index
contains a Configure
widget that only affects its set of results. Both Hits
display results for the index they’re targeting, using the same query, but with a different number of hits per page.
React
Search the same index with different search parameters
Multi-index search doesn’t always mean searching in different indices. Sometimes, you may want to search in the same index, but with different search parameters. This can be useful, for example, when storing different types of content in a single Algolia index, or when you want to surface specific items based on an attribute. In this situation, make sure to include anindexId
on each Index
.
React
Search multiple indices with Autocomplete
You can use the Autocomplete library in your InstantSearch app to build a dynamic multi-source search experience. For example, you may want to display Query Suggestions together with recent searches, create a multi-column layout that mixes facets and item previews, or even dynamically change sources based on the query.Autocomplete isn’t limited to Algolia indices: you can use static sources or fetch data from other APIs.
- Integrate Autocomplete with React InstantSearch
- Include multiple result types
- Reshape sources
- Create a multi-column layout
Category display
Algolia can help you display both category matches and results if you:- Add categories to your Query Suggestions either inline or listed below a result. For example, you might see the following in your Query Suggestions list “game of thrones in Books”
- Use multi-index search to display categories from a separate category index. This is useful if you want to display categories and Query Suggestions at the same time. Clicking such a result typically redirects to a category page. The following is a sample dataset for a product index and a category index.
Example product index
JSON
Example category index
JSON
Next steps
You now have a good starting point to create an even richer experience with React InstantSearch. You could improve this app by:- Implementing routing to sync your UI with the browser URL.
- Checking the API reference to discover more Hooks.