When you run a promotional sale on your online store, you’ll see an influx of higher-than-usual traffic as visitors search for their desired products.
If you’re not prepared, your website could be in danger of lagging or even crashing due to the spike in visitors and search queries. Of course, you can recover your site easily enough if you use good managed WordPress hosting. But it’s not a great situation to be in when you’re looking to satisfy the needs of all those new customers, and retain them as well.
So how do you handle all those requests? One great option is Elasticsearch.
Though WordPress’s default search is limited in its functionalities (it doesn’t allow fuzzy search or match with categories and taxonomies), the platform is open-source, meaning a score of developers have made a significant contribution to improving the search functionality. Among the broad range of search functionality plugins is Elasticsearch, which not only enhances the result of a search but also helps in improving website performance.
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, to the point that it’s integrated within our hosting platform.
In this tutorial, you’ll learn how to configure Elasticsearch on WordPress. This is simpler than 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 that 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.
Cloudways provide elastic search FREE on 1-click.
Explore all features Now
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 7.6. And ElasticPress plugin also supports 7.6 version.
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 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.
Customer Review at
“Beautifully optimized hosting for WordPress and Magento”
Arda Burak [Agency Owner]