Imagine you are an online store owner and suddenly on the day you are running a promotional sale, high traffic starts to come in and they all want to search their desired products using WordPress default search feature?
If your site has a large number of products, chances are that it will start to lag or possibly crash due to a large number of search queries from the visitors. If your site is hosted on a managed WordPress cloud hosting it can be recovered easily. Something you would never want especially when you are hosting a large number of visitors.
The WordPress default search is a combination of queries like “LIKE” and “%query%”. It doesn’t allow the fuzzy search, even when someone makes a simple typo mistake, it does not perform the search effectively.
One other limitation in WordPress is that it only searches and matches the words that are in the title and content, and it doesn’t match with categories and taxonomies as such.
For this reason, WordPress has been in the midst of a lot of criticism from users. Since it is an open-source platform, a lot of WordPress developers have made a significant contribution to improving the search functionality. WordPress now offers a broad range of plugins to optimize search functionality. One such option is the Elasticsearch, which not only enhances the result of a search but also helps in improving website performance.
In this tutorial, we are going to learn how to configure Elasticsearch on WordPress. It is an integrated part of our hosting platform, and we are quite huge fans of this search enhancement service. To get an idea of what exactly Elasticsearch is and how it works, you should read the blog post by our Co-Founder, Aaqib Gadit here. This post should give you a fair idea of why Cloudways fell in love with this innovative search feature.
Anyhow, coming back to WordPress, one must know that it is not as difficult to configure Elasticsearch on WordPress as it looks, especially if you are an active customer of Cloudways. So here is how it is done!
What is Elasticsearch?
Elasticsearch was released in 2010 and is the tool used to run search queries faster in large databases. Unlike conventional searches; Elasticsearch is extremely fast around raw data and is a highly scalable search engine. Elasticsearch has an extensive API which can be integrated into any web application including WordPress for big data discovery.
Elasticsearch in WordPress plays an integral part as we all know the poor and slow performance of its default searching capabilities. It may look OK on a site with small databases but it gets painful for the visitors trying to find their product from 50 different categories. Elasticsearch offers real-time index updates that add a new document to the index almost instantaneously.
Why Use Elasticsearch?
Large websites with directories and archives on various categories can take advantage of Elasticsearch. Online stores with thousands of products can reduce the searching time by using Elasticsearch in WordPress. This also improves the user experience as it can customer can further narrow down their search queries to get to the desired product faster.
Another amazing feature of Elasticsearch is the ability of monitoring application in real time. This indexes the search data and makes logs for future analysis. It is a useful feature for e-commerce stores who wish to see the trends on customer’s buying behavior and set their marketing strategies accordingly.
Configure Elasticsearch on WordPress on Cloudways
First of all, to configure Elasticsearch on WordPress, you must keep the following points in mind:
- You need to have an account at Cloudways and have backups in place.
- You should be comfortable with editing WordPress files.
- You should be familiar with WP-CLI.
Step 1: Enable Elasticsearch
In the Cloudways Platform, you can enable Elasticsearch from the “Settings & Packages” tab under the “Servers” screen.
This will enable Elasticsearch on your current server.
Note: Cloudways supports Elasticsearch up to version 6.5, but the ElasticPress plugin is compatible with 6.2 yet. Please make sure you select Elasticsearch 5.4 from the drop-down.
Step 2: Install ElasticPress on WordPress
According to Taylor Lovett, Project Lead ElasticPress and Director of Web Engineering at 10up:
“MySQL is inherently not created for complex search queries. Elasticsearch, on the other hand, is. To achieve highly relevant search results, filtration, or any other sort of advanced search functionality with WordPress, Elasticsearch is pretty much required. ElasticPress is the easiest and most effective way to integrate Elasticsearch with WordPress.”
According to Chris Wiegman, the Senior Web Engineer at 10up:
“ElasticPress integrates WordPress’ search with the Elasticsearch, offering an inexpensive way to make users’ search experience more useful. It offers powerful advanced search features with infinitely scalable features, by offloading the search to a service designed specifically to handle this need at large scale.”
To install ElasticPress which is a WordPress elasticsearch plugin, log in to your WordPress dashboard and add a new plugin by searching for ElasticPress.
Step 3: Edit the wp-config.php File
Next, we need to define IP and port where Elasticsearch is running from. On Cloudways, Elasticsearch is operating from the same server as our WordPress website.
Edit your wp-config.php file and define EP_HOST as below.
/** ElasticPress */ define( 'EP_HOST', 'http://127.0.0.1:9200' );
Note: I added the local IP as ElasticPress runs on the same server as my WordPress and consider it as a local environment, else, you need to mention the server IP address where Elasticsearch is installed
If you are unable to upload the updated wp-config.php file, you may need to reset permission by navigating to Application Management → Application Settings.
This will connect your WordPress site to Elasticsearch on your server through ElasticPress plugin. Get back to WordPress Dashboard → ElasticPress and click on Sync.
Step 4: Build Indexes and Activate Elasticsearch
Finally, log in to your SSH terminal through Cloudways Platform and build the ES indexes and activate the feature.
To log in to SSH terminal, head over to Server and then Launch SSH Terminal or use Putty to connect to your server.
From the top left bar, click on Applications and then get into your specific application. From the right side, create Application Credentials that will be used to access the application via SSH and SFTP.
Now, head back to the SSH Terminal window and use the above credentials to get into the application.
Similarly, you can also access your application directly from SSH Terminal present inside your server dashboard.
Simply, launch the terminal and login with your master credentials.
Inside your terminal window, run ‘cd applications’ command to access the applications running on this server. And type ‘ls’ to get the list of applications.
You could have just one or twenty applications running on your server. In order to access the one you need to work on, simply type the following command
cd [name of the application] cd [name of the folder]
That’s it! You are in the desired folder of your desired application.
WP-CLI is a required to run ElasticPress specific commands. On Cloudways, each WordPress instance comes pre-installed with WP-CLI.
First, run the following command to build ES indexes.
wp elasticpress index --setup
You will see output such as this:
ES usually activates itself after running the index. But to be on the safer side, run this command to make sure it is enabled.
wp plugin activate elasticpress
Deploying Elasticsearch on WordPress or WooCommerce websites will improve the search experience and improve the capability of your site to handle more search queries. Especially, for a WooCommerce site as a number of search increases on an e-commerce website.
For more insight on the supported commands of ElasticPress in WP-CLI, navigate here.
On Cloudways, you get WP-CLI and Elasticsearch pre-installed. If you are not on Cloudways then you will need to first install WP-CLI on your server and then Elasticsearch. Quite a hassle? Time-consuming? Then let us take care of all your installation hassles and save your time by signing up on the most optimized cloud hosting platform.
What is the best WordPress Elasticsearch plugin?
We have already seen ElasticPress in action which is by far the simplest and effective plugin. However, there are other plugins available with additional functionalities such as WPSOLR which is a paid plugin.
Start Growing with Cloudways Today!
We never compromise on performance, security, and support.