Default search feature in WordPress is known to be notoriously bad and slow. So, when high traffic comes to your WordPress website that has larger databases, then there is a high possibility that your site may crash. Although your technical support team can overcome site crashes in a matter of minutes and leave a lasting impact on the credibility of your website. You may ultimately result in losing some of the potential customers coming to your site.
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.
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!
How to 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.
As discussed earlier, it is not a complex setup, and even a beginner can configure it using this step-by-step tutorial.
Step 1: Enable ElasticSearch
In the Cloudways Platform, you can enable ElasticSearch from the “Settings & Packages” tab under the “Server” screen.
This will enable ElasticSearch on your current server.
Note: Cloudways supports ElasticSearch up to the version 5.4, but the ElasticPress plugin is compatible with 5.3 yet. Please make sure you select Elasticsearch 2.4 from the drop-down.
Step 2: Install ElasticPress on WordPress site
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, 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, 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' );
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: Building Indexes and Activating 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.
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.
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 an 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 your 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 ecommerce 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.
Start Creating Web Apps on Managed Cloud Servers Now!
Easy Web App Deployment for Agencies, Developers and E-Commerce Industry