How to optimize Elasticsearch for WooCommerce online stores

Table of Contents


If you’re running an online store, the chances are that you’re using WooCommerce, one of the most popular e-commerce platforms for WordPress. WooCommerce stores produce a considerable amount of data that needs to be efficiently managed, and Elasticsearch is an ideal solution for organizing and querying huge amounts of data. Elasticsearch is a highly scalable and distributed search engine that can be used to optimize your WooCommerce store. The following steps will help you to optimize Elasticsearch for WooCommerce online stores.

Step 1: Update Elasticsearch Settings

The first step you need to take to optimize Elasticsearch is to update its settings. Elasticsearch comes with some default settings that may not be good enough for your online store. You can make the necessary changes using the Elasticsearch API. Here is some PHP code that you can embed in your HTML file to update your Elasticsearch settings:

$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_URL, 'https://localhost:9200/_cluster/settings');
curl_setopt($ch, CURLOPT_POSTFIELDS, '{"persistent":{"cluster":{"routing":{"allocation":{"awareness":{"attributes":"rack_id"}}}}}}}');

With this code, you can change your Elasticsearch settings to suit your online store’s needs.

Step 2: Use Elasticsearch to Optimize WooCommerce

After updating your Elasticsearch settings, you can use Elasticsearch to optimize your WooCommerce store. Elasticsearch can provide fast and accurate search results, which can help your customers find the products they need quickly. Elasticsearch can also help you improve your store’s performance by reducing the load on your MySQL server. Here is some PHP code that you can embed in your HTML file to use Elasticsearch to optimize your WooCommerce store:

$params = [
    'index' => 'woocommerce',
    'type' => 'product',
    'body' => [
        'query' => [
            'match' => [
                'name' => 'red shoes'

$response = $client->search($params);


This code will search for products that have the keyword “red shoes” in their name. You can modify this code to search for other keywords and get more accurate search results.

Step 3: Monitor Elasticsearch Performance

Monitoring your Elasticsearch performance is crucial to ensure that it’s functioning correctly and providing optimum results. Elasticsearch provides monitoring tools to help you identify any issues with your cluster’s performance. Here is some PHP code that you can embed in your HTML file to monitor your Elasticsearch performance:

$params = [
    'index' => '_stats',
    'type' => 'indexing,search',

$response = $client->indices()->stats($params);

This code will provide you with indexing and search statistics, which can help you identify any performance issues with your Elasticsearch cluster.

How WPSOLR can help

WPSOLR is a plugin that can help you integrate Elasticsearch with WooCommerce seamlessly. It provides an intuitive and user-friendly interface that allows you to manage your Elasticsearch cluster easily. WPSOLR takes care of complex Elasticsearch settings, and you don’t need any technical knowledge to use it. WPSOLR also provides advanced search features that can help you increase your online store’s sales. With WPSOLR, you can get superior search results and faster page loading times, which can enhance your customers’ experience.


Elasticsearch is an excellent solution for optimizing your WooCommerce online store. It provides scalable and robust search capabilities that can help you handle your store’s data more efficiently. By following the steps outlined in this article and using the WPSOLR plugin, you can benefit from Elasticsearch’s power and improve your store’s user interface.

Read more related content