Configure elasticsearch on Magento 2

Since Magento 2.4 elasticsearch is no longer just an option. It's a requirement, as the MySQL search functionality has been removed from the code base.

You need to configure elasticsearch BEFORE upgrading to Magento 2.4. If upgrading without elasticsearch you will be met with an error:

Catalog Search index exception: Could not ping search engine: No alive nodes found in your cluster

To get started you need an elasticsearch instance from powerhosting. Please contact us a support@powerhosting.dk to get more info.

You can either chose to configure this from the Magento 2 administration, or via ssh and cli commands. If you have started the upgrade without Elasticseach configured you can only fix this via ssh.

Configure elasticsearch via ssh and cli

Many developers prefer working via cli. To configure elasticsearch for Magento 2 you need to run the following commands while standing in the magento root folder:

magerun2 config:store:set --scope-id 0 --scope=default 'catalog/search/elasticsearch7_server_hostname' '<elastic hostname>'
magerun2 config:store:set --scope-id 0 --scope=default 'catalog/search/elasticsearch7_server_port' '80'
magerun2 config:store:set --scope-id 0 --scope=default 'catalog/search/elasticsearch7_enable_auth' '1'
magerun2 config:store:set --scope-id 0 --scope=default 'catalog/search/elasticsearch7_username' '<elastic username> '
magerun2 config:store:set --scope-id 0 --scope=default 'catalog/search/elasticsearch7_password' '<elastic password>'
magerun2 config:store:set --scope-id 0 --scope=default 'catalog/search/elasticsearch7_index_prefix' '<prefix of your choice>'

Watch the video for a detailed walkthrough.

Configure elasticsearch via Magento 2 admin