How to Use Elasticsearch to Speed Up WordPress Search

Updated on July 19, 2018

Elasticsearch is an open-source full-text search engine. It is used to index data and search that data incredibly quickly.

In the context of WordPress, Elasticsearch can be used to speed up querying of the WordPress database. This is done by building an index of the content of your site’s database and then using Elasticsearch to search this index much more quickly than a MySQL query is capable of performing the same search.

If you have the time and ability, Elasticsearch can be integrated with a WordPress site by a highly knowledgeable WordPress and Elasticsearch developer. If your site makes relatively standard use of WP_Query, Elasticsearch can also be integrated by installing ElasticPress, a free WordPress plugin from 10up, available from WordPress.org, which automatically integrates with the WP_Query object to generate query results with Elasticsearch rather than MySQL.

Sites That Will Benefit Most from Elasticsearch

Any site that makes heavy use of WP_Query can benefit from Elasticsearch. Examples of sites that can benefit from Elasticsearch:

  • Sites where search is the primary means of navigation.
  • WooCommerce sites with a huge number of orders where site admins need to be able to search the list of orders regularly.
  • Any site with a large number of posts where MySQL queries are producing unacceptably slow results.

If your site has queries that run unacceptably slow, or if you believe that heavy querying is overloading your site’s database, it may be a good candidate for Elasticsearch.

Adding Elasticsearch to a Site at Kinsta

If you would like to add Elasticsearch to your site hosted at Kinsta, follow these steps:

  1. Contact Kinsta’s support team and request to have Elasticsearch added to your site.
  2. Kinsta’s support team will install Elasticsearch in your site container and our billing team will add the Elasticsearch add-on subscription to your account. Having Elasticsearch installed on the same server as your PHP environment and MySQL database helps to decreases latency as opposed to hosting it in a separate instance or using hosted Elasticsearch from Elastic.
  3. Kinsta’s support team will also go ahead and install the ElasticPress plugin on your site and connect it to the Elasticpress service running in the site container.
    ElasticPress WordPress plugin

    ElasticPress WordPress plugin

    A few features of ElasticPress include: showing WooCommerce products in search results, autocompletion of searches, choosing what you want to index, and improvements to queries for related posts. If you plan to use a different plugin or build your own integration please let our support team know and they will skip this step.

If you do opt to discontinue using Elasticsearch you may ask to have it removed from your site container and you should ask to have the add-on subscription canceled.  You will receive a refund of any unused subscription fees issued according to our refund policy.

Important note if your site has both a STAGING and a LIVE environment: Elasticsearch must be installed in your STAGING and LIVE environments separately. If our support team installs Elasticsearch in one environment and then that environment is overwritten (backup restored, staging pushed live), Elasticsearch will be overwritten and removed from the container. Please plan Elastisearch installation carefully in cooperation with our support team to ensure Elasticsearch is not inadvertently removed during the setup process.

Using Elasticsearch with a WordPress Website

Once Elasticsearch has been installed it must be integrated with your site. The most common method of integrating your site with Elasticsearch is to install ElasticPress. During typical setup, our support team will install the ElasticPress plugin and connect it to the Elasticsearch service.

Following installation, you will need to access the website admin area and complete setup of the ElasticPress plugin. Part of that process is indexing the content of your site. If the content of your site is extremely large indexing via the WordPress admin may fail. In that case, if you have a Business 1 plan or higher, you can use the ElasticPress wp-cli commands to perform indexing over SSH.

If your site makes use of custom fields and you wish to search the content of the custom fields custom development work may be required to cause ElasticPress to index and search those field.

Limits to Kinsta’s Support for Elasticsearch

Elasticsearch can accept queries passed to it locally on the server or over a RESTful API. At Kinsta, only local access to Elasticsearch is possible. Passing requests to Elasticsearch over the RESTful API is not possible and the necessary ports cannot be opened to accept these requests. If you need to pass HTTP requests to the site to be queried it will be necessary to pass the query to WordPress over the WP REST API or using an Ajax call.

We do not support or install any Elasticsearch add-on products such as Kibana or Logstash. Use of Elasticsearch on our platform is limited to integration of the service with WordPress to support faster queries.

Kinsta’s support for Elasticsearch is limited to installing Elasticsearch and any required dependencies in the site container, installing the ElasticPress plugin, and ensuring that Elasticsearch is available for use by WordPress. Integrating Elasticsearch with your website is the responsibility of each website owner and if you find that you need assistance with proper integration of Elasticsearch with your website – including the indexing and searching of custom fields – you will need to retain the services of a qualified WordPress developer.

Was this article helpful?
No, or there was something off

Hand-picked related articles

Use WordPress?

Use WordPress?

Join 20,000+ others who get our FREE weekly newsletter with WordPress tips on how to drive more traffic and revenue to your business!

Consent

You have Successfully Subscribed!