Skip to main content
Signature
index({
  indexName: string,
  // Optional parameters
  indexId?: string,
});

Import

import { index } from "instantsearch.js/es/widgets";

About this widget

This widget lets you apply widgets to a specific index. It’s useful when building interfaces that target multiple indices such as federated searches. The position of index in the widgets tree affects which search parameters apply. Widgets that create search parameters forward them to their child index widgets.
JavaScript
search.addWidgets([
  searchBox(),
  hits(),

  index({ indexName: "instant_search" }).addWidgets([
    // The index inherits from the parent's `searchBox` search parameters
    hits(),
  ]),
]);
The only exception to this rule is when two widgets own the same part of your UI state, like two searchBox widgets or two refinementList widgets on the same attribute. In that case, the latter takes precedence and overrides the search parameters.
JavaScript
search.addWidgets([
  searchBox(),
  hits(),

  index({ indexName: "instant_search" }).addWidgets([
    // The index does not inherit from the parent's `searchBox` search parameters
    searchBox(),
    hits(),
  ]),
]);
The same rule applies when you nest multiple index widgets.

Examples

JavaScript
index({ indexName: "instant_search" }).addWidgets([
  // Add widgets
  // ...
]);

Options

indexName
string
required
The index to search into.
JavaScript
index({
  indexName: "instant_search",
});
indexId
string
default:"value provided for indexName"
An identifier for the index widget.Providing an indexId lets different index widgets target the same Algolia index. It’s helpful for routing. It lets you find the refinements that match an index widget.
JavaScript
index({
  // ...
  indexId: "instant_search_one",
});

Methods

addWidgets
Adds widget(s) to the index.
JavaScript
const index = index({
  indexName: "instant_search",
});

const searchBox = searchBox({
  // ...
});

const hits = hits({
  // ...
});

index.addWidgets([searchBox, hits]);
removeWidgets
Removes widget(s) from the index widget. To be properly removed, the widget instances you pass must have a dispose() method.
JavaScript
const index = index({
  indexName: "instant_search",
});

const searchBox = searchBox({
  // ...
});

const hits = hits({
  // ...
});

index.removeWidgets([searchBox, hits]);
I