4

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.

Thanks.

1 Answer 1

9

Found a way 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"
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.