Setting up ElasticSearch

As of version 2.3.1 Magento comes with compatibility for elastic search.

You should familiarise yourself with the magento documentation

Install the Java JDK

Elastic search 6 requires Java to be installed.

yum install java-1.8.0-openjdk

Following the docs for installing elastic search 6.8 you should:

Import the PGP key

sudo rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch

Add the elasticsearch repo

Create the repo file

sudo vim /etc/yum.repos.d/elasticsearch.repo

Add the contents:

1
2
3
4
5
6
7
8
[elasticsearch-6.x]
name=Elasticsearch repository for 6.x packages
baseurl=https://artifacts.elastic.co/packages/6.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md

Install elasticsearch

sudo yum install elasticsearch

Start and enable elasticsearch

sudo systemctl enable elasticsearch

sudo systemctl start elasticsearch

Check elasticsearch is working

curl -X GET "localhost:9200/?pretty"

Lock down elasticsearch

You need to make sure that elasticsearch is locked down and inaccessible from outside the server. We only want magento to be able to access elastic search.

Configeure Magento to work with elasticsearch

Head to Stores > Settings > Configuration > Catalog > Catalog > Catalog Search.

Config Item Value
Elasticsearch Server Hostname localhost
Elasticsearch Server Port 9200(or whatever port elastic search is listening on)
Elasticsearch Index Prefix magento2(magento default, if multiple stores are using same elastic search you can change)
Enable Elasticsearch HTTP Auth No
Elasticsearch Server Timeout 15

Match the config above and then hit the Test Connection button.

If that is successful you can run bin/magento indexer:reindex and bin/magento cache:clean and you should start seeing results.

Troubleshooting

No results are showing

Fielddata is disabled on text fields by default.

The exception message: Fielddata is disabled on text fields by default. Set fielddata=true on [%attribute%] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead.

Solution here.