Skip to main content
To search in multiple entities at the same time, use aggregators. Aggregators let you index multiple entities in a single index.

Define aggregators

To create a new aggregator, add a new class to your entities directory. The getEntities method of this class should return all the entity classes you want to index:
PHP
If you’re using a NoSQL database like MongoDB, use the Algolia\SearchBundle\Document\Aggregator class instead. Finally, add the new aggregator class name to the config/packages/algolia_search.yaml file:
YAML
An aggregator is a standard entity class. To start searching entities on the aggregator, use the search method of your SearchService:
PHP
Be careful, the $result array may contain different types of entities instances.
To get the raw results from Algolia, use the rawSearch method. However, each result might have a different structure:
PHP
JSON
To ensure that each result has a similar structure, implement the normalize method on each entity or override it on the aggregator class.

Conditional indexing

Conditional indexing on aggregators works just like a normal entity, using the index_if key. Use $this->entity to have access to the current entity being aggregated. Here is an example using the method approach:
YAML
PHP
For more information, see Conditional indexing.
Last modified on June 12, 2026