Videos tutorials
Video – Install Elasticsearch on Ubuntu
Video – Install Elasticsearch on CentOS
Video – Install Elasticsearch on Windows
Requirements
WPSOLR was Last tested with Elasticsearch 6.2.2.
Elasticsearch 5.2 is the first version introduced and tested in WPSOLR. Elasticsearch 2.x will not work, due to change of type mappings.
You will also need the ingest attachments plugin if you need to search files.
Learn how to install and configure Elasticsearch in a docker container
Configure and install Elasticsearch
Elasticsearch is a search and analytics platform designed for scalability and speed. Elasticsearch offers powerful search and analytical capabilities, making it suitable for a wide range of use cases, from text-based search engines to log and event data analysis.
We are going to use docker containers to host the different applications. To install the docker engine, use the following link : https://docs.docker.com/engine/install/.
Also, don’t forget to install docker-compose.
The Elasticsearch official documentation can be found here : https://www.elastic.co/guide/en/elasticsearch/reference/current/setup.html.
Elasticsearch uses a great amount of memory maps, so you have to add this line to /etc/sysctl.conf :
vm.max_map_count = 262144
This will increase the amount of virtual memory maps of your host machine the docker container can use.
You can create the “docker-compose.yml” file :
version: '3.9'
services:
elasticsearch:
image: elasticsearch:8.11.3
volumes:
- elasticsearch-config:/usr/share/elasticsearch/config/
ports:
- 9200:9200
networks:
- my-elasticsearch-network
networks:
my-elasticsearch-network:
volumes:
elasticsearch-config:
This will download the official Elasticsearch image and start a container from this image with :
- port bindings : the 9200 port of the container (the port used by the Elasticsearch service) will be binded to the 9200 port of your host machine. This means that you can communicate with the docker container through the 9200 port of your host machine.
- volume : this will set the Elasticsearch config directory in your container as a volume called “elasticsearch-config” present in your host machine’s file system. This way you can modify the configuration files outside of your container CLI.
- networks : this is so that if you have other docker containers, they can communicate with eachother if they are in the same network (in this case “my-elasticsearch-network”).
You can start the service using the following command on your host machine :
docker-compose up -d
Disable SSL (https)
To disable SSL (or https), you can modify the “/usr/share/elasticsearch/config/elasticsearch.yml” in the docker container :
#----------------------- BEGIN SECURITY AUTO CONFIGURATION -----------------------
#
# The following settings, TLS certificates, and keys have been automatically
# generated to configure Elasticsearch security features on 11-04-2024 13:10:17
#
# --------------------------------------------------------------------------------
# Enable security features
xpack.security.enabled: false #previously true
xpack.security.enrollment.enabled: false #previously true
# Enable encryption for HTTP API client connections, such as Kibana, Logstash, and Agents
xpack.security.http.ssl:
enabled: false #previously true
keystore.path: certs/http.p12
# Enable encryption and mutual authentication between cluster nodes
xpack.security.transport.ssl:
enabled: false #previously true
verification_mode: certificate
keystore.path: certs/transport.p12
truststore.path: certs/transport.p12
# Create a new cluster with the current node only
# Additional nodes can still join the cluster later
cluster.initial_master_nodes: ["a9dce418c848"]
After restarting the service, you can verify that the modifications were applied using :
curl "https://localhost:9200/"
Add Elasticsearch to your WordPress
You can easily add Elasticsearch to your WordPress with no extra cost by using the WPSolr Free plugin. It can add standard search, Ajax search and facets to your WordPress.
Setup your WordPress website
You can create your WordPress container by adding the following to your “docker-compose.yml” :
version: '3.9'
services:
wp:
image: wordpress:php8.2-apache
volumes:
- wp-data:/var/www/html
ports:
- 80:80
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
networks:
- backend-wpd
- frontend-wpd
db:
image: mysql:5.7
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
networks:
- backend-wpd
elasticsearch:
image: elasticsearch:8.11.3
volumes:
- elasticsearch-config:/usr/share/elasticsearch/config/
ports:
- 9200:9200
networks:
- frontend-wpd
networks:
frontend-wpd:
backend-wpd:
volumes:
wp-data:
Once you have setup your WordPress container, you can setup WPSolr. WPSolr is a search plugin that can integrate many search engines (including Elasticsearch) into any WordPress website.
Setup WPSolr WordPress plugin
This guide details how to setup WPSolr to integrate Elasticsearch into your WordPress.