How to Configure Elasticsearch on WordPress Imagine that you are an online store owner and suddenly the day you are running a promotional sale, it starts to come in high traffic and they want to find all the products you want by using the WordPress default search feature?
In this case, if there is a large number of products on your site, then it is likely that it will start interrupting or possibly crashing due to a large number of search queries from visitors. Meanwhile, If your site is hosted on managed WordPress cloud hosting, it can be easily retrieved. When you are hosting a large number of visitors, you never want to especially.
Why use the Elasticsearch?
Large websites with directories and archives on different categories can benefit from the search elastic. Online stores with thousands of products can reduce search time by using Elasticsearch in WordPress. This also improves the user’s experience as customers can further reduce their search queries to get the desired product faster.
Another amazing feature of Elasticsearch is the ability of the monitoring app in real-time. It indexes search data and creates logs for future analysis. This is a useful feature for e-commerce stores, who want to see trends in customer buying behavior and determine their marketing strategy accordingly.
Configure Elasticsearch on WordPress
First of all, to configure Elasticsearch on WordPress, you have to keep the following points in mind:
- You should be comfortable in editing WordPress files
- You should be familiar with WP-CLI.
As discussed earlier, this is not a complex setup, and even a beginner can also configure it using this step-by-step tutorial.
How to Configure Elasticsearch on WordPress
Step 1: Enable and Configure Elasticsearch
This will enable Elasticsearch on your current server.
Step 2: Install ElasticPress on the WordPress site
install ElasticPress which is a WordPress Elastics Search plugin, log into your WordPress dashboard, and add a new plugin by searching ElasticPress.
Step 3: Edit the wp-config.php file
Next, we need to define the IP and the port from which ElasticPress is going on. Elasticsearch as our website is working from the same server.
Edit your wp-config.php file and define EP_HOST as described below.
/ ** ElasticPress * / Defined ('EP_HOST', 'http://127.0.0.1:9200');
Note: I have added the local IP because ElasticPress runs on the same server as my WordPress and considers it as a local environment, otherwise, you need to mention that server IP address where Elasticsearch is installed
If you are unable to upload the updated wp-config.php file, you should reset permissions by navigating to Application Management? Application settings.
This will connect your WordPress site to Elasticsearch on your server via the ElasticPress plugin. Go back to WordPress Dashboard? ElasticPress and click on Sync, for example, check the image.
Step 4: Building Indexing and Activating Configure Elasticsearch
Finally, log in to your SSH terminal through the Cloudways platform and build the ES index and activate the feature.
To log in to SSH terminal, go to Server and then Launch SSH Terminal or use Putty to connect to your server.
From the top left, click on Apps and then go to your specific application. From the right side, create Application Credentials which will be used to access the app through SSH and SFTP.
Now, finally, go back to the SSH terminal window and use the above credentials to get into the app.
Similarly, you can also access your application directly from the SSH terminal inside your server dashboard.
Launch terminal and login with your master credentials.
Inside your terminal window, run the CD app command to access the applications running on this server. Type ‘ ls and to get the list of applications.
Only one or twenty applications can run on your server. To access the one you need to work on, just type the following command
CD [application name]
CD [folder name]
You are in the desired folder of the application you want.
WP-CLI is required to run ElasticPress specific commands. Each WordPress instance comes pre-installed with WP-CLI.
First, run the following command to create the ES index.
1 wp elastarpress index --setup
You will see the output in this way:
Then, as usual, it activates itself after running the index. But to be safe, run this command to enable it.