JavaScript
You are currently reading the documentation for InstantSearch.js v4.
Read the migration guide to learn how to upgrade from v3 to v4. You can still access the V3 documentation for this page.
Search multiple indices with InstantSearch
The following demo uses an InstantSearch search box to display hits from two different indices:Open CodeSandbox
Run and edit the Multi-index search example in CodeSandbox.
Explore source code
Browse the source for the Multi-index search example on GitHub.
searchBox to search multiple indices. It adds the first hits widget at the top level, while the second one is scoped under an index widget. The second hits widget just displays results from the Algolia index referenced by the index widget that precedes it. The first hits widget displays results from the top level instant_search index.
All examples in this guide assume you’ve included InstantSearch.js in your web page from a CDN.
If, instead, you’re using it with a package manager, adjust how you import InstantSearch.js and its widgets for more information.
JavaScript
index.
The following example displays a different number of hits for the two sets of results.
The instant_search index displays 8 results and instant_search_price_desc 16 results.
To restrict the number of results per page, use the configure widget.
Each widget is scoped under the targeted level.
JavaScript
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 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.
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