cancel
Showing results for 
Search instead for 
Did you mean: 

Configure Elasticsearch engine CLI

Configure Elasticsearch engine CLI

Story:

We need to setup elasticsearch on Magento 2 when a new container starts. We have post-install scripts that could handle that and not have someone go into the admin and manually do it.

 

How to do it:

We added these commands to our post-install script:

magento config:set catalog/search/engine 'elasticsearch5'
magento config:set catalog/search/elasticsearch5_server_hostname 'elasticsearch-hostname.env'

You can also configure other things like ports:

magento config:set catalog/search/elasticsearch5_server_port '9200'
magento config:set catalog/search/elasticsearch5_index_prefix 'magento2'
magento config:set catalog/search/elasticsearch5_enable_auth '0'
magento config:set catalog/search/elasticsearch5_server_timeout '15'

These are the engine options:

mysql - MySQL
elasticsearch - Elasticsearch
elasticsearch5 - Elasticsearch5.0+

If you decide to use variables on the server_hostname, you must use double quotes:

magento config:set catalog/search/elasticsearch5_server_hostname "elasticsearch-$MY_VARIABLE.env"

You can use these commands manually or Ansible or any other way you install Magento.