Shopware - Setting Up Elasticsearch

This article describes how to integrate Elasticsearch into Shopware 6 to improve your search results and performance, as well as how to perform an initial indexing.


Prerequisites

  • Shopware installation / server
  • Elasticsearch server
  • Permissions for the Customer Center configuration module


Please note that Advanced Search 2.0 is no longer compatible with Elasticsearch as of Shopware 6.6.X; OpenSearch must be used instead.



Preparing the Elasticsearch Server

Create a VPC network and add an additional network interface to your Elasticsearch server with an IP address from the VPC network.

For the Shopware server, an additional network interface with an IP address from the corresponding VPC network so that a successful connection between the servers can be established.

Next, open the Elasticsearch server configuration file elasticsearch.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
xpack.security.http.ssl: enabled: true xpack.security.http.ssl: enabled: false Disable enforced SSL/TLS for the REST API. When using our pre-installed Elasticsearch, this option is already preconfigured.
http.host: 127.0.0.1 http.host: ["127.0.0.1", "10.20.0.11"] IP addresses to which the Elasticsearch server provides the service. In this case, the service is provided exclusively locally on the server and to the VPC IP address.


Customizing the Kibana Configuration

If you wish to continue using Kibana after customizing Elasticsearch, you must adjust the configuration via the configuration module in our Customer Center.

Open the Kibana configuration file kibana.yml via the Configuration Module in the Customer Center:

Default setting New / additional setting Description
elasticsearch.hosts: ['https://127.0.0.1:9200'] elasticsearch.hosts: ['http://127.0.0.1:9200'] IP addresses to which the Elasticsearch server provides the service. In this case, the service is provided exclusively locally on the server and for the VPC IP address.
xpack.fleet.outputs: [{id: fleet-default-output, name: default, is_default: true, is_default_monitoring: true, type: elasticsearch, hosts: ['https://127.0.0.1:9200'], ca_trusted_fingerprint: 7f2e903da1e1d13cd3f82d1715f1d7ec6d06b3a6a0d6def461296d3d10106e9e}] xpack.fleet.outputs: [{id: fleet-default-output, name: default, is_default: true, is_default_monitoring: true, type: elasticsearch, hosts: ['http://127.0.0.1:9200'], ca_trusted_fingerprint: 7f2e903da1e1d13cd3f82d1715f1d7ec6d06b3a6a0d6def461296d3d10106e9e} Disable forced SSL/TLS for the REST API. If you are using our pre-installed Elasticsearch, this option is already preconfigured.



Shopware Frontend Configuration

To connect Elasticsearch 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 Elasticsearch server:

OPENSEARCH_URL=http://elastic:<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 Elasticsearch 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



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:

bin/console dal:refresh:index     (Rebuild the entire 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, the mapping may need to be updated if certain products cannot be found:

 bin/console es:mapping:update


If you are using various plugins that may affect search functionality in Shopware, have set up custom fields or similar features for products, or have made other customizations, you may need to make further adjustments to ensure that indexing produces the desired results. Depending on the Shopware version you’re using, additional variations may occur here.


Shopware Administration Configuration

You can also use Elasticsearch for indexing the administration area. To do this, extend your .env.local file as follows:

# Elasticsearch Admin Configuration
ADMIN_OPENSEARCH_URL=http://elastic:<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.