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 database, chances are that it will start to lag or possible crash due to poor performing search or if it is not on managed WordPress cloud hosting. 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.
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 highly scalable search engine. Elasticsearch has an extensive API which can be integrated to 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 adds a new document to the index almost instantaneously.
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
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.
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.
Q: What is the best WordPress Elasticsearch plugin?
Ans: 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.
Be the first to check out WordPress 5.0
Use our Staging feature before upgrading your website to WordPress 5.0.