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

# Searching Multiple Indices

> Learn how to search across multiple Algolia indices simultaneously with DocSearch

DocSearch supports searching multiple Algolia indices in a single query, allowing you to aggregate results from different data sources like documentation, blog posts, API references, and more.

## Using the `indices` Prop

The `indices` prop accepts an array of index configurations. Each index can be specified as a string (index name only) or as an object with index-specific search parameters.

### Basic Multiple Indices

Search across multiple indices with default settings:

```jsx theme={null}
import { DocSearch } from '@docsearch/react';

<DocSearch
  appId="YOUR_APP_ID"
  apiKey="YOUR_SEARCH_API_KEY"
  indices={[
    'documentation',
    'blog_posts',
    'api_reference'
  ]}
/>
```

## Index-Specific Search Parameters

Each index can have its own search parameters to customize how results are retrieved and ranked:

```jsx theme={null}
<DocSearch
  appId="YOUR_APP_ID"
  apiKey="YOUR_SEARCH_API_KEY"
  indices={[
    {
      name: 'documentation',
      searchParameters: {
        hitsPerPage: 10,
        attributesToRetrieve: [
          'hierarchy.lvl0',
          'hierarchy.lvl1',
          'hierarchy.lvl2',
          'content',
          'url'
        ],
        facetFilters: ['version:latest']
      }
    },
    {
      name: 'blog_posts',
      searchParameters: {
        hitsPerPage: 5,
        attributesToSnippet: ['content:20'],
        filters: 'published = true'
      }
    },
    'api_reference' // String format uses defaults
  ]}
/>
```

<Note>
  The `indices` prop replaces the deprecated `indexName` and `searchParameters` props. While the old props still work for backward compatibility, new implementations should use `indices`.
</Note>

## TypeScript Interface

```typescript theme={null}
interface DocSearchIndex {
  name: string;
  searchParameters?: SearchParamsObject;
}

interface DocSearchProps {
  // ... other props
  indices?: Array<DocSearchIndex | string>;
}
```

## Common Search Parameters

When configuring index-specific parameters, you can use any Algolia search parameter:

### Filtering Results

```jsx theme={null}
indices={[
  {
    name: 'documentation',
    searchParameters: {
      facetFilters: ['language:en', 'version:v2'],
      filters: 'category:tutorial OR category:guide'
    }
  }
]}
```

### Controlling Result Display

```jsx theme={null}
indices={[
  {
    name: 'documentation',
    searchParameters: {
      hitsPerPage: 15,
      attributesToSnippet: [
        'hierarchy.lvl1:10',
        'content:15'
      ],
      snippetEllipsisText: '…',
      highlightPreTag: '<mark>',
      highlightPostTag: '</mark>'
    }
  }
]}
```

### Analytics

```jsx theme={null}
indices={[
  {
    name: 'documentation',
    searchParameters: {
      clickAnalytics: true
    }
  }
]}
```

<Note>
  When `insights` is enabled at the top level, `clickAnalytics` is automatically enabled for all indices unless explicitly overridden.
</Note>

## Mixing with Other Features

### Multiple Indices with Ask AI

You can use multiple indices for keyword search while configuring Ask AI separately:

```jsx theme={null}
<DocSearch
  appId="YOUR_APP_ID"
  apiKey="YOUR_SEARCH_API_KEY"
  indices={[
    'documentation',
    'blog_posts'
  ]}
  askAi={{
    assistantId: 'your-assistant-id',
    indexName: 'documentation', // AI searches only this index
    searchParameters: {
      facetFilters: ['language:en']
    }
  }}
/>
```

### Multiple Indices with transformItems

The `transformItems` function receives hits from all indices:

```jsx theme={null}
<DocSearch
  appId="YOUR_APP_ID"
  apiKey="YOUR_SEARCH_API_KEY"
  indices={['docs', 'blog', 'api']}
  transformItems={(items) => {
    return items.map((item) => {
      // Add a badge based on index
      const indexName = item.__autocomplete_indexName;
      return {
        ...item,
        hierarchy: {
          ...item.hierarchy,
          lvl0: `[${indexName}] ${item.hierarchy.lvl0}`
        }
      };
    });
  }}
/>
```

## Migration from Deprecated Props

<Warning>
  The `indexName` and top-level `searchParameters` props are deprecated and will be removed in a future version.
</Warning>

### Before (Deprecated)

```jsx theme={null}
<DocSearch
  appId="YOUR_APP_ID"
  apiKey="YOUR_SEARCH_API_KEY"
  indexName="documentation"
  searchParameters={{
    hitsPerPage: 10,
    facetFilters: ['version:latest']
  }}
/>
```

### After (Recommended)

```jsx theme={null}
<DocSearch
  appId="YOUR_APP_ID"
  apiKey="YOUR_SEARCH_API_KEY"
  indices={[
    {
      name: 'documentation',
      searchParameters: {
        hitsPerPage: 10,
        facetFilters: ['version:latest']
      }
    }
  ]}
/>
```

## Best Practices

<Card title="Performance" icon="zap">
  Keep the number of indices reasonable (typically 2-5) to maintain fast search performance.
</Card>

<Card title="Result Limits" icon="list">
  Use `hitsPerPage` and `maxResultsPerGroup` to control how many results appear from each index.
</Card>

<Card title="Relevance" icon="star">
  Use index-specific `facetFilters` and `filters` to ensure results are relevant to the current context (e.g., user's selected version, language, or category).
</Card>

## Complete Example

Here's a complete example searching across documentation, blog, and API reference indices:

```jsx theme={null}
import { DocSearch } from '@docsearch/react';
import '@docsearch/css';

function App() {
  return (
    <DocSearch
      appId="YOUR_APP_ID"
      apiKey="YOUR_SEARCH_API_KEY"
      indices={[
        {
          name: 'documentation',
          searchParameters: {
            hitsPerPage: 10,
            facetFilters: ['version:v2', 'language:en'],
            attributesToRetrieve: [
              'hierarchy.lvl0',
              'hierarchy.lvl1',
              'hierarchy.lvl2',
              'hierarchy.lvl3',
              'content',
              'type',
              'url'
            ]
          }
        },
        {
          name: 'blog_posts',
          searchParameters: {
            hitsPerPage: 5,
            filters: 'published = true',
            attributesToSnippet: ['content:20']
          }
        },
        {
          name: 'api_reference',
          searchParameters: {
            hitsPerPage: 8,
            restrictSearchableAttributes: ['method', 'endpoint', 'description']
          }
        }
      ]}
      maxResultsPerGroup={5}
      insights={true}
    />
  );
}
```
