Using Solr 8 and Solr 9 on Drupal
Information on using Pantheon Search with Solr 8 and Solr 9 on Drupal, including setup, upgrade, and troubleshooting
Pantheon Search gives Drupal web teams a high-performance search index integrated with Integrated Composer's one-click updates. Pantheon Search supports both Apache Solr 8 and Solr 9. Solr 9 builds on the foundation of Solr 8 with improved performance, more secure defaults, and new search capabilities.
Solr Features
For more information, refer to the Drupal Search API Solr documentation.
Custom Processors
Search API module processors provide a variety of configuration options for your Pantheon Search results, like boosting results based on dates, taxonomy terms, or specific content types, controlling access to content based on permissions, and adding highlighted excerpts to results.
Refer to the Search API module processors documentation for details.
Before You Begin
Drupal Site Setup
Pantheon Search with Solr can be used on Drupal sites. You can set up a new Drupal site or visit the Drupal upgrade and migration guide to create a Drupal site.
Prepare the Local Environment
Ensure you review our documentation on Git, Composer, and Terminus, and have them installed and configured on your local machine. Pantheon requires Composer 2 at a minimum.
-
Mac users can use Homebrew to install Git, Composer, and PHP, along with their required dependencies. Restart the shell or terminal environment after entering the following command:
-
Windows users should install the following dependencies:
Enable Pantheon Search
Enable Pantheon Search under Settings in your Pantheon Site Dashboard. This feature is available for sandbox sites as well as paid plans at the Professional level and above.
Each Pantheon environment (Dev, Test, Live, and Multidevs) has its own Solr server. Indexing and searching in one environment does not impact any other environment.
Using the Site Dashboard
-
Navigate to the site and environment you would like to configure.
-
Click Settings.
-
Click Add Ons > Apache Solr: Add.
Using Terminus
Enter the following command. Replace $SITE with the specified name of the site:
The solr:enable and solr:disable commands are deprecated as of Terminus 4.1.6. Use search:enable and search:disable instead.
Configure the Solr Version
Add or update the following in your pantheon.yml file before installing the Drupal search module to avoid incompatibilities.
If no search version is specified in pantheon.yml, Pantheon defaults to Solr 3. Explicitly set the version to avoid running an outdated Solr version.
Push the changes to pantheon.yml. A confirmation message is returned in Git, which is also visible in the Site Dashboard's commit history within Code tab. The pantheon.yml file follows code through environments as you promote it, enabling the Solr server in each environment automatically.
For more information, refer to the documentation on Specifying a Solr version.
Install the Search API Pantheon Module
Composer automatically installs the following dependencies when you install drupal/search_api_pantheon:
- Solarium — a Solr client library for PHP.
- Search API — Drupal's module for indexing content entities.
- Search API Solr — connects Search API to Apache Solr. Version 4.3.x or later is required for Solr 9 compatibility.
-
Clone the Git repository for the desired environment from the Pantheon Site Dashboard.
-
Enter the following command in the terminal to run
composer install: -
Add the Search API Pantheon module as a required dependency:
-
You should now have the Search API Pantheon module installed along with its dependencies. You can run
git statusto verify that onlycomposer.jsonandcomposer.lockwere modified. -
Commit and push the changes, Integrated Composer will take a few moments to install these on your site.
For Solr 9, install the beta release instead:
Version 8.5.x is currently in beta. Test thoroughly on non-production environments and report issues in the drupal.org issue queue.
- Run
git statusto verify that onlycomposer.jsonandcomposer.lockwere modified. - Commit and push the changes. Integrated Composer will take a few moments to install these on your site.
Enable the Search API Pantheon Module
Navigate to Admin > Extend (/admin/modules) and enable Search API Pantheon. Enabling this module also enables Search API and Search API Solr if they are not already enabled.
You can also enable it from the command line using Terminus and Drush replacing $ENV with the environment:
Verify the Installation
Navigate to Configuration > Search & Metadata > Search API in the Drupal Admin interface. Confirm that the Pantheon Search server and Primary index exist and are enabled.
Configure Pantheon Search
When you enable the Search API Pantheon module, a default Primary index is automatically created and linked to the Pantheon Search server. You can use this index or create a custom one.
Each environment has its own Solr core with its own indexed data. While the Search API index configuration deploys with your code via config management, the indexed content does not transfer between environments. After deploying to a new environment, you must re-index content by running terminus drush <site>.<env> -- search-api:index or allowing cron to index content incrementally.
Add Search Index
Navigate to Configuration > Search & Metadata > Search API within Drupal's Admin interface. The server labeled Pantheon Search should be displayed with an enabled status.
Using the Primary Index: Select the Primary index to use the default index automatically created when the module was enabled.
Creating a Custom Index:
- Click Add Index.
- Give the index a name and select a datasource. If this is your first time using Search API, select Content to index your site's nodes.
- Select Pantheon Search as the Server.
- In the Index Options panel, ensure Index items immediately is checked.
- Click Save to add the new index.
The Index status page should indicate that the newly created index was successfully saved.
Add Fields to the Index
- Click the Fields tab and click Add fields.
- Add the fields you want to search, such as Title and Body.
- Click Save changes when you are finished.
Post the Schema
Post the schema to the Solr server before indexing content:
The [path] argument is optional. Provide it only if you want to use a custom config set directory. If omitted, the default config set matching the installed Search API Solr version is used.
Index Content
- Click Index now on the View tab of your index's Overview page to populate the index with your content. Content will also be indexed automatically when cron runs.
- Click Search API to return to the Search API overview page at
admin/config/search/search-api.
Both the server and index you just created should be displayed on the page.
Upgrading from Solr 8 to Solr 9
Version 8.5.x of the Search API Pantheon module is currently in beta. Test thoroughly on non-production environments and report issues in the drupal.org issue queue.
Switching from Solr 8 to Solr 9 provisions a new Solr core and requires a full reindex, so search will be unavailable or return incomplete results until reindexing is complete.
Update the module before switching pantheon.yml. This order ensures the correct Solr 9 schema and connector are in place before Pantheon provisions the new Solr 9 server.
-
Update the module:
-
Update your
pantheon.yml: -
Clear the cache:
-
Post the schema for the new Solr version:
Wait a few minutes for the platform to provision the new Solr 9 core. Verify the core is ready by running the diagnose command or checking the server status page (
admin/config/search/search-api> Pantheon Search), then post the schema: -
Clear the index and reindex content:
After switching Solr versions, Drupal's index tracker may still show items as indexed from the old core. Running
drush search-api:clearresets the tracker and queues all content for reindexing, which is processed whendrush search-api:indexruns. -
Test search functionality thoroughly on non-production environments. Use
terminus drush $SITE.$ENV -- search-api-pantheon:diagnoseto verify the configuration.
Rolling Back to Solr 8
For some reason if you need to revert to Solr 8 after upgrading, the search_api_pantheon 8.5.x module supports both Solr 8 and Solr 9, so you do not need to downgrade the module version.
-
Change
pantheon.ymlback toversion: 8: -
Commit and push the change:
-
Clear the cache:
-
Re-post the Solr 8 schema:
-
Clear the index and reindex content:
Upgrading from 8.4.x to 8.5.x
If you are upgrading from 8.4.x and want to continue using Solr 8, no migration is needed:
-
Update the module:
-
Clear the cache:
If you were previously running Search API Solr 4.2.x or earlier, you must also resolve a schema incompatibility. See Schema incompatibility with Search API Solr 4.3.x below.
Troubleshooting
Schema incompatibility with Search API Solr 4.3.x
Search API Solr 4.3.x introduced fundamental schema changes that are incompatible with indexes created by 4.2.x or earlier. This affects any site upgrading the module to 4.3.x, regardless of Solr server version. After upgrading, you may encounter the following error:
If you are upgrading to Solr 9, you can skip the below section. The Solr 9 upgrade process already requires a full reindex, which resolves this incompatibility.
Resolving this requires clearing all indexed data and performing a full reindex. Plan for temporary search downtime.
-
Post the updated schema:
-
Disable and re-enable the Solr server to clear all tracked index data:
Find your
<server_id>withterminus drush $SITE.$ENV -- search-api:server-list. -
Reload the Solr core:
-
Wait at least 5 minutes, then verify the schema version has updated:
The platform checks for new schemas and issues a core reload within 1-5 minutes.
-
Re-enable all indexes (they are automatically disabled when the server is disabled):
-
Reindex all content:
-
Verify search functionality is working as expected.
Incorrect Solr Version
This error is indicative of Solr 3 being active when Solr 8 is expected:
When running drush sapi-search commands, you may also see:
This can be fixed by updating pantheon.yml to use Solr 8.
Diagnose Issues
The diagnose command drush search-api-pantheon:diagnose (sapd) checks the Search API install and returns an error for any part that is not working.
The drush search-api-pantheon:select (saps) command runs the query against the Solr server. It is recommended that you use ?debug=true on any Solr page to allow a query to pass.
Deploy an Updated config.zip to your Solr Server
If the Search API Solr displays the following after the Search module is installed:
It is advisable to download and deploy an updated
config.zipto your Solr server.
This message can safely be ignored. It resolves once a search index has been created and the schema files have been posted.
Fatal error: Cannot redeclare config_get_config_directory()
This error occurs after installing search_api_pantheon for Drupal using Composer. If you receive this error, you should switch to the Drupal Composer-managed Upstream. See Switch Your Custom Upstream for instructions on how to do this.