Skip to main content
The AlgoliaSearchBundle connects your Doctrine entities to Algolia. It keeps your Algolia in sync when you create, update, or delete entities. Its source code is open source under the MIT license.

Before you begin

You need:
  • An Algolia account
  • PHP 8.2 or later for Symfony 7, or PHP 8.4 or later for Symfony 8
  • The PHP pdo_sqlite extension
  • Symfony 7 or 8
  • Composer
These requirements are for AlgoliaSearchBundle 8.1. For older Symfony versions, see Compatibility. To upgrade from 8.0.x to 8.1.x, see Upgrade the Algolia SearchBundle.

Set up the bundle

Set up the bundle in a new Symfony app. Then index and search an entity.
1

Create a Symfony app

To create a new Symfony app and add Doctrine, run:
To store the data of this test in a local SQLite database, add the following line to a .env.local file:
.env.local
2

Install the bundle

To add the bundle to your composer.json file and install it, run:
To register the bundle, add the following entry to config/bundles.php:
config/bundles.php
3

Add your credentials

The bundle needs your Algolia and . It loads them from the ALGOLIA_APP_ID and ALGOLIA_API_KEY environment variables. To set them, add the following lines to your .env.local file:
.env.local
Replace ALGOLIA_APPLICATION_ID and ALGOLIA_API_KEY with your Algolia credentials. Find both in the Algolia dashboard. To run this test, use an API key with the search and addObject ACL.
To create Algolia applications and API keys from the command line, use the Algolia CLI.
4

Create an entity

To create a Contact entity, add the following file:
src/Entity/Contact.php
To create the database table, run:
5

Connect the entity to Algolia

To send your entity to Algolia, add it to the bundle’s configuration. Create the following file:
config/packages/algolia_search.yaml
By default, the bundle prefixes index names with the Symfony environment followed by an underscore character: _. In the dev environment, it stores the entity’s records in an index named dev_contacts. To change the prefix, set the prefix option.
6

Index a record

To add a record to the database, run:
To send all Contact entities to Algolia, run:
If the setup works, the command prints Indexed 1 / 1 App\Entity\Contact entities into dev_contacts index.
7

Search the record

To search from your app, add a controller that uses the SearchService:
src/Controller/SearchController.php
Algolia indexes records asynchronously, so wait 5 seconds. Then, to start a local server, run:
In a second terminal, to search for the record, run:
If the setup works, the command prints ["Jon Doe"].Each run of search:import updates the same record, so your test index stays small.To remove the indexed test data, delete the dev_contacts index in the Algolia dashboard or with the Algolia CLI. This deletes the index and its settings. The contact is stored separately in your SQLite database.

Keep your index in sync

After you configure an index, the bundle updates it whenever you create, update, or delete entities through Doctrine. Raw SQL bypasses Doctrine. After inserting or updating rows with SQL, run search:import. To learn more about importing data, including zero-downtime reindexing, see Send data to Algolia.

Use more bundle commands

Commands such as search:clear and search:settings:push need more permissions than the test in this guide. To run them, use an API key with the matching ACL, such as deleteObject and editSettings.

Next steps

Last modified on November 30, 2026