Integrations / Platforms / Magento 2 / Indexing

To provide fast and relevant search, the Algolia extension for Magento Open Source and Adobe Commerce takes your products, categories, and pages from your store and transforms them into searchable data. This process is called indexing.

You can index your data through these methods:

  • Automatically with an indexing queue
  • Manually from the Magento console
  • Manually on the command-line

Check the troubleshooting guide if you have any issues with your data, indexes, or queue.

To provide the best search experience for your users, the extension automatically keeps all your data up to date, offering two indexing mechanisms in Magento:

  • Section reindex. An entire section of the catalog (products, categories, pages) is uploaded to Algolia’s servers and reindexed.
  • Single item reindex. - A single resource (product, category, page) is uploaded to the servers and reindexed. Single item reindexing happens when a resource is updated.

By default, the indexing operations run synchronously, and you must wait until the indexing process finishes before you can continue. This is inconvenient and can have unexpected side effects. Therefore, you should instead use the indexing queue, which processes all index operations in the background and avoids some sources of errors.

Section reindex with an indexing queue

The indexing queue uses temporary indices to reindex products. Instead of updating the production index directly, Algolia creates a copy and replaces the production index only when the update is complete.

This approach has several advantages:

  • Higher reindexing speed
  • No inaccuracies with deleted products
  • Fewer indexing operations

Changes to the index will be visible once the temporary index completely replaces the production index.

Section reindex without an indexing queue

Without the indexing queue, reindexing the complete catalog is synchronous: everything has to wait until the process completes.

Processing large indices synchronously may trigger PHP timeouts.

Without a queue, reindexing takes more time and resources. It’s also less reliable: if products are updated while the reindexing is in process, the data on Algolia’s servers may not be up to date.

Enable the indexing queue for any full reindexing, especially if you have large catalogs.

Automatic indexing

The Algolia extension for Magento sends every change and deletion on products or categories to Algolia’s servers to keep all data up to date.

Manual indexing

If you want to index your data manually, first turn off the indexing queue: set Stores > Configuration > Algolia Search > Indexing Queue/Cron > Enable Indexing Queue to No in the Magento dashboard.

You can now use the command-line to send manual updates to Algolia’s server. For example, to completely reindex all products:

1
php path/to/magento/bin/magento indexer:reindex algolia_products

Use the same command for all other indices created by the extension:

algolia_products Reindex all products
algolia_categories Reindex all categories
algolia_pages Reindex all CMS pages
algolia_suggestions Reindex all search query suggestions
algolia_additional_sections Reindex all additional sections
algolia_queue_runner Process jobs in the indexing queue
algolia_delete_products Remove inactive products from Algolia indices

Indexing products

Learn more about configuring product search for Magento 2 in the Algolia Academy

Visit Algolia Academy

It’s essential for your business to have exact and up-to-date product data in your search.

Full reindexing

To fully reindex all your products:

1
php path/to/magento/bin/magento indexer:reindex algolia_products

Indexable products

To prevent too many indexed products and save indexing operations, Algolia only indexes products that actually appear in the online store.

Algolia only indexes products that are:

  • Visible - either in the catalog, the search, or both
  • Enabled
  • Not deleted
  • In stock - unless Magento is configured to show out-of-stock products, too.

If you miss a product in your search, make sure the product meets all four criteria.

Searchable attributes

You can configure which attributes should be searched when users type their queries. To configure the list of searchable attributes, go to Stores > Configuration > Algolia Search > Products.

Configure product search with Algolia in Magento 2

In the Products tab, you can set each attribute as searchable, retrievable, or ordered. By default, all attributes are set to be searched as unordered. This is usually the best choice, and you shouldn’t change it without specific reasons.

Default searchable attributes

Some attributes are always indexed, regardless of your configuration. These attributes aren’t all searchable but can be used for filtering, sorting, customizing the ranking, and building the results page.

These attributes are always indexed:

name The product’s name
url The product’s URL
visibility_search The product’s visibility in the search
visibility_catalog The product’s visibility in the catalog
categories The product’s categories, formatted as a tree path
categories_without_path The product’s categories, without the tree path
thumbnail_url The product’s thumbnail image
image_url The product’s main image
in_stock The product’s stock availability
price The product’s price
type_id The product’s type (simple, configurable, bundled, etc.)

Facets

Facets are attributes used to filter search results. Common facets include price, color, categories, and brand. You may need to adjust the facets of the products you sell and how your users search for these products.

For each facet, you can specify:

  • The attribute
  • The label - this will be displayed above the filter
  • The type of facet

Configuration of facets

You can make facets searchable. This allows users to search for a facet value with a separate search box in the user interface. This is useful when a facet has a lot of different values, like with brands, for example.

You can attach facets to Rules. If you set Create Query rule to Yes, Algolia uses the attribute as a filter. Suppose you create a Rule for the color attribute and users search for products with a specific color, for example, “red shorts”. In that case, Algolia filters all results with “red” as the color attribute.

When a Rule is attached to an attribute, it’s applied in both the Autocomplete menu and Instant Search Results page.

Rules are a feature only available on Premium plans.

By default, the extension provides facets on the price, categories, and color attributes. Any numeric attribute, for example, price, is shown as a slider in the user interface.

Attributes specified as facets are automatically indexed as retrievable but not searchable. You don’t need to add them manually to the searchable attributes.

Sorting strategies

Sorting is only available on the Instant Search Results page.

When searching for products, users may expect multiple ways to sort the result set. For example, they want to sort by relevance, popularity, price, or date.

The default sorting strategy when searching is sorting by relevance. Any other sorting strategy needs to be defined in the Sort Settings. For each strategy, an attribute, sort order (ascending or descending) and label should be defined.

Configure sorting strategies

By default, there are three sorting strategies:

  1. From lowest price to highest price
  2. From highest price to lowest price
  3. From newest to oldest

Each sorting strategy creates a new standard replica index, which increases the number of records. Find more information in the FAQ.

Attributes configured for sorting are automatically indexed as retrievable but not searchable. You don’t need to add them manually to the searchable attributes.

Removing a sorting strategy doesn’t automatically remove the replica index replica in Algolia. You need to delete replica indices manually.

Index settings

Configure these settings in the Magento dashboard:

Manage additional index settings in the Algolia dashboard. To change the settings programmatically, you can hook into the algolia_products_index_before_set_settings event provided by the extension. See Custom back-end events for more information.

Any changes in the Algolia dashboard override these settings until you perform a full reindex from the Magento dashboard.

Indexing categories

To keep the number of records and indexing operations as low as possible, Algolia only indexes active categories. To show all categories in the Autocomplete menu and Instant Search Results page, set Show categories that are not included in the navigation menu to Yes.

Show categories that are not included in the navigation menu configuration

Full reindexing

1
php path/to/magento/bin/magento indexer:reindex algolia_categories

Searchable attributes

You can configure which attributes should be searched when users type their queries. To configure the list of searchable attributes, go to Stores > Algolia Search > Categories.

In the Categories tab, you can set each attribute as searchable, retrievable, or ordered. By default, all attributes are set to be searched as unordered. This is usually the best choice, and you shouldn’t change it without specific reasons.

Default searchable category attributes

Some attributes are always indexed, regardless of your configuration. These attributes aren’t all searchable but can be used for filtering, sorting, customizing the ranking, and building the results page.

These attributes are always indexed:

name The category’s name
url The category’s URL
path The category’s path (parent categories)
level The category’s level in the category tree
include_in_menu The category’s visibility in the menu
_tags Filled automatically by the extension
popularity The category’s popularity
product_count The category’s amount of products

Index settings

Configure these settings in the Magento dashboard:

Manage additional index settings in the Algolia dashboard. To change the settings programmatically, you can hook into the algolia_categories_index_before_set_settings event provided by the extension. See Custom back-end events for more information.

Any changes in the Algolia dashboard override these settings until you perform a full reindex from the Magento Dashboard.

Indexing pages

The Algolia extension automatically indexes CMS pages, allowing users to search for pages in the Autocomplete menu. All active pages are indexed by default.

Configuration of excluded pages

You can exclude specific pages, like error pages, so they don’t appear in the search results. Turn off this indexing of pages in Additional Sections.

Configuration of additional sections

Full reindexing

1
php path/to/magento/bin/magento indexer:reindex algolia_pages

Searchable attributes

You can’t configure the searchable attributes for pages in the Magento dashboard. However, you can change them programmatically, by hooking into the algolia_after_create_page_object event provided by the extension. See Custom back-end events for more information.

Default searchable page attributes

These attributes are indexed by default and aren’t all searchable (some are). You can use them for filtering, sorting, custom ranking and building the search results page.

These attributes are always indexed:

name The page’s name
url The page’s URL
slug The page’s slug
content The page’s content

Since records for the Algolia search engine have to be smaller than 10 kilobytes, any page with more than 10,000 characters won’t be indexed. In this case, only the page’s name would be searchable.

For more information about the engine’s record limit, see Index and Record Size and Usage Limitations

Index settings

The following settings are always set and can’t be changed through the admin interface:

Manage additional index settings in the Algolia dashboard. You can also change the settings programmatically, by hooking into the algolia_pages_index_before_set_settings event provided by the extension. See Custom Back End Events for a list of events provided by the extension.

Any changes in the Algolia dashboard override these settings until a full reindex is performed from the Magento Dashboard.

Indexing suggestions

Magento stores every query, the number of results, and the number of searches in the catalogsearch_query table in the database.

Magento only stores back-end searches. As-you-type searches aren’t stored.

Algolia’s Magento extension lets you index queries that are performed regularly. In the settings, you can filter relevant queries, for example, by the minimum number of results or minimum popularity. You can add the resulting queries to Algolia’s Query Suggestions index, providing a list of suggestions for the most relevant queries on this Magento installation.

Configure suggestions

To ensure the data in the suggestion index is relevant, enable back-end search with the Algolia extension by turning on Enable Search and Make SEO Request in the Magento dashboard.

With these options enabled, the extension processes back-end searches. Since the data in catalogsearch_query is also updated, the queries in this table will become more relevant over time.

By default, suggestions aren’t indexed. When enabling the indexing of suggestions, you need to trigger a manual reindex. Another way to start the indexing of suggestions is by adding a recurring job to the cron table:

1
1 * * * * php path/to/magento/bin/magento indexer:reindex algolia_suggestions

Instead of Magento suggestions, you can also use Algolia’s Query Suggestions feature.

Full reindexing

1
php path/to/magento/bin/magento indexer:reindex algolia_suggestions

Searchable attributes

You can’t configure searchable attributes for suggestions in the Magento dashboard. However, you can change them programmatically by hooking them into the algolia_after_create_suggestion_object event provided by the extension.

See Custom back-end events for more information.

Default searchable query attributes

These attributes are always indexed and aren’t all searchable. You can use these attributes for filtering, sorting, custom ranking, and building the search results page.

These attributes are always indexed:

query The query’s value
number_of_results The query’s number of results
popularity The query’s number of searches
updated_at The query’s last update timestamp

Index settings

The following settings are always set and can’t be changed in the Magento dashboard:

Manage additional settings in the Algolia dashboard. To change the settings programmatically, you can hook into the algolia_suggestions_index_before_set_settings event provided by the extension. See Custom back-end events for more information.

Any changes in the Algolia dashboard override these settings until you perform a full reindex from the Magento dashboard.

Indexing additional sections

The Autocomplete menu lets you display other sections from attributes, such as colors and brands.

For this feature to work, you must enable the Instant Search Results page.

The attributes used for the additional sections have to be set as attributes for faceting.

Configuration of additional sections

1
php path/to/magento/bin/magento indexer:reindex algolia_additional_sections

Searchable attributes

Manage additional index settings in the Algolia dashboard. It’s also possible to change the settings programmatically, by hooking into the algolia_additional_sections_index_before_set_settings event provided by the extension.

See Custom Back End Events for a list of events provided by the extension.

Default searchable attributes

These attributes are indexed by default and aren’t all searchable (some are). They can be used for filtering, sorting, customizing the ranking and building the results page.

The attributes that are always indexed:

value The attributes’ value, for example, Red, XL, Nike.

Index settings

The following settings are always set and can’t be changed through the admin interface:

Manage additional index settings in the Algolia dashboard. It’s also possible to change the settings programmatically, by hooking into the algolia_additional_sections_index_before_set_settings event provided by the extension. See Custom Back End Events for a list of events provided by the extension.

Any changes in the Algolia dashboard override these settings until a full reindex is performed from the Magento Dashboard.

Removing inactive products

To remove products from your Algolia index, use the algolia_delete_products indexer:

1
php path/to/magento/bin/magento indexer:reindex algolia_delete_products

This indexer removes all products from Algolia indices that you don’t want to include in your search. This can be useful when you delete or deactivate products directly in Magento’s database, and the extension could reindex and remove them regularly.

The reindexer doesn’t delete products from your Magento database. Products are only removed from Algolia indices.

Did you find this page helpful?