> ## Documentation Index
> Fetch the complete documentation index at: https://algolia.com/llms.txt
> Use this file to discover all available pages before exploring further.

# index

> Scopes a group of widgets to a specific index in multi-index search interfaces.

<div className="not-prose algolia-flavor-switcher">
  <div className="afs-dropdown">
    <div className="afs-trigger" role="button" tabIndex="0" aria-haspopup="listbox">
      <span className="afs-current">JavaScript</span>

      <svg className="afs-chevron lucide lucide-chevron-down" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
        <path d="m6 9 6 6 6-6" />
      </svg>
    </div>

    <ul className="afs-menu" role="listbox">
      <li role="option" aria-selected="true"><a className="afs-option is-current" href="/doc/api-reference/widgets/index-widget/js"><span className="afs-option-name">JavaScript</span><span className="afs-option-lib">InstantSearch.js</span></a></li>
      <li role="option" aria-selected="false"><a className="afs-option" href="/doc/api-reference/widgets/index-widget/react"><span className="afs-option-name">React</span><span className="afs-option-lib">React InstantSearch</span></a></li>
      <li role="option" aria-selected="false"><a className="afs-option" href="/doc/api-reference/widgets/index-widget/vue"><span className="afs-option-name">Vue</span><span className="afs-option-lib">Vue InstantSearch</span></a></li>
    </ul>
  </div>
</div>

```ts Signature theme={"system"}
index({
  indexName: string,
  // Optional parameters
  indexId?: string,
});
```

## Import

<CodeGroup>
  ```js Package manager theme={"system"}
  import { index } from "instantsearch.js/es/widgets";
  ```

  ```js CDN theme={"system"}
  const { index } = instantsearch.widgets;
  // or directly use instantsearch.widgets.index()
  ```
</CodeGroup>

<Card title="See this widget in action" icon="monitor-play" href="https://instantsearchjs.netlify.app/stories/js/?path=/story/basics-index--default" horizontal>
  Preview this widget and its behavior.
</Card>

## 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](/doc/guides/building-search-ui/ui-and-ux-patterns/multi-index-search/js).

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.

```js JavaScript icon=code theme={"system"}
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`](/doc/api-reference/widgets/search-box/js) widgets
or two [`refinementList`](/doc/api-reference/widgets/refinement-list/js) widgets on the same attribute.
In that case, the latter takes precedence and overrides the search parameters.

```js JavaScript icon=code theme={"system"}
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

```js JavaScript icon=code theme={"system"}
index({ indexName: "instant_search" }).addWidgets([
  // Add widgets
  // ...
]);
```

## Options

<ParamField body="indexName" type="string" required>
  The index to search into.

  ```js JavaScript icon=code theme={"system"}
  index({
    indexName: "instant_search",
  });
  ```
</ParamField>

<ParamField body="indexId" type="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`](/doc/api-reference/widgets/instantsearch/js#param-routing).
  It lets you find the refinements that match an `index` widget.

  ```js JavaScript icon=code theme={"system"}
  index({
    // ...
    indexId: "instant_search_one",
  });
  ```
</ParamField>

## Methods

<ParamField body="addWidgets">
  Adds widget(s) to the index.

  ```js JavaScript icon=code theme={"system"}
  const index = index({
    indexName: "instant_search",
  });

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

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

  index.addWidgets([searchBox, hits]);
  ```
</ParamField>

<ParamField body="removeWidgets">
  Removes widget(s) from the `index` widget. To be properly removed, the widget instances you pass must have a `dispose()` method.

  ```js JavaScript icon=code theme={"system"}
  const index = index({
    indexName: "instant_search",
  });

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

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

  index.removeWidgets([searchBox, hits]);
  ```
</ParamField>
