Skip to main content
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:
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:
<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
  ]}
/>
The indices prop replaces the deprecated indexName and searchParameters props. While the old props still work for backward compatibility, new implementations should use indices.

TypeScript Interface

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

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

Controlling Result Display

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

Analytics

indices={[
  {
    name: 'documentation',
    searchParameters: {
      clickAnalytics: true
    }
  }
]}
When insights is enabled at the top level, clickAnalytics is automatically enabled for all indices unless explicitly overridden.

Mixing with Other Features

Multiple Indices with Ask AI

You can use multiple indices for keyword search while configuring Ask AI separately:
<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:
<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

The indexName and top-level searchParameters props are deprecated and will be removed in a future version.

Before (Deprecated)

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

Best Practices

Performance

Keep the number of indices reasonable (typically 2-5) to maintain fast search performance.

Result Limits

Use hitsPerPage and maxResultsPerGroup to control how many results appear from each index.

Relevance

Use index-specific facetFilters and filters to ensure results are relevant to the current context (e.g., user’s selected version, language, or category).

Complete Example

Here’s a complete example searching across documentation, blog, and API reference indices:
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}
    />
  );
}

Build docs developers (and LLMs) love