Shopware - Setting Up OpenSearch
This article describes how to integrate OpenSearch into Shopware 6 to improve your search results and performance, as well as how to perform an initial indexing.
Prerequisites
- Shopware installation / server (Shopware 6.5.X or higher)
- OpenSearch server
- Permission for the Customer Center configuration module
Preparing the OpenSearch Server
Create a VPC network and add an additional network interface to your OpenSearch server with an IP address from the VPC network.
Open the OpenSearch server configuration file opensearch.yml via the Configuration Module in the Customer Center to set up the connection to Shopware via the VPC network.
To do this, change the following settings or add them if they do not yet exist, and save them so that the updated configuration is transferred to the server and becomes active:
| Default Setting | New / Additional Setting | Description |
|---|---|---|
| #cluster.name: my-application | cluster.name: shopware | Cluster name |
| #node.name: node-1 | node.name: XXXXX | Server name |
| (not available by default) | http.bind_host: ["127.0.0.1", "10.20.0.X"] | IP addresses to which the OpenSearch server exposes the service. In this case, the service is provided exclusively locally on the server and for the VPC IP address. |
| #cluster.initial_cluster_manager_nodes: ["node-1", "node-2"] | cluster.initial_cluster_manager_nodes: [“XXXXX.creolineserver.com"] | Cluster nodes |
| plugins.security.ssl.http.enabled: true | plugins.security.ssl.http.enabled: false | Disable enforced SSL/TLS for the REST API. When using our OpenSearch pre-installation, this option is already preconfigured. |
| (not available by default) | plugins.security.ssl_only: false | Disables enforced SSL/TLS in general. If you are using our OpenSearch pre-installation, this option is already preconfigured. |
Shopware Frontend Configuration
To connect OpenSearch to Shopware, you must first enter the following connection information and general settings in the .env.local configuration file of your Shopware installation. You can find the login credentials in the password vault of your OpenSearch server:
OPENSEARCH_URL=http://admin:<Password>@10.20.0.X
SHOPWARE_ES_ENABLED="1"
SHOPWARE_ES_INDEXING_ENABLED="1"
SHOPWARE_ES_INDEX_PREFIX="<prefix name>" In the next step, create the following configuration file:
nano /var/www/vhosts/<DocumentRoot>/httpdocs/config/packages/elasticsearch.yml If you are using a single OpenSearch server, insert the following content:
elasticsearch:
hosts: "%env(string:OPENSEARCH_URL)%"
index_settings:
number_of_shards: 1
number_of_replicas: 0 Next, clear the Shopware cache as follows so that the updated configuration takes effect:
bin/console cache:clear Caution: Make sure the command is executed by the system user of the Shopware instance.
Perform Initial Frontend Indexing
If you have used OpenSearch or Elasticsearch in the past, we recommend removing all old indexes and associated settings that are no longer needed from Shopware using the following commands before generating a new index:
bin/console es:index:cleanup (Remove all unused indexes)
bin/console es:reset (Reset all OpenSearch / Elasticsearch indexes) Then completely rebuild the index:
# Rebuild the entire index
bin/console dal:refresh:index
bin/console es:index Depending on the number of products, media files, etc., completely regenerating the index can take a very long time. Furthermore, it may be necessary to increase the PHP memory limit so that the process can be completed successfully.
In some cases, aliases may need to be generated if certain products cannot be found:
bin/console es:create:alias If you use various plugins that may affect search functionality in Shopware, set up custom fields or similar features for products, and so on, you may need to make additional adjustments to ensure that indexing achieves the desired result. Depending on the Shopware version you’re using, additional variations may occur here.
Shopware Administration Configuration
You can also use OpenSearch for indexing the administration area. To do this, extend your .env.local file as follows:
# OpenSearch Admin Configuration
ADMIN_OPENSEARCH_URL=http://admin:<Password>@10.20.0.X
SHOPWARE_ADMIN_ES_ENABLED=1
SHOPWARE_ADMIN_ES_REFRESH_INDICES=1
SHOPWARE_ADMIN_ES_INDEX_PREFIX="admin_test" Next, clear the Shopware cache as follows so that the updated configuration takes effect:
bin/console cache:clear Initial Administration Indexing
If you have used OpenSearch or Elasticsearch in the past, we recommend removing all old indexes and associated settings that are no longer needed from Shopware using the following commands before generating a new index:
bin/console es:admin:reset (Reset all OpenSearch / Elasticsearch indexes) Then completely rebuild the index:
bin/console es:admin:index (Create index for administration) Depending on the number of products, media files, etc., completely regenerating the index can take a very long time. Furthermore, it may be necessary to increase the PHP memory limit so that the process can be completed successfully.
Please also note that the use of plugins or custom search settings can significantly affect the actual results. Depending on the Shopware version you are using, additional variations may occur.