Site icon WebDevStudios

Why Use Elasticsearch on Your WordPress Site?

What Is Elasticsearch?

Elasticsearch is an incredibly fast, open-source, distributed, and highly-scalable solution for managing your searchable content. Elasticsearch can scale up with your site, because of its distributed architecture. This means that as your site grows, Elasticsearch grows with it; and it still provides performance benefits. One of the main advantages of Elasticsearch is to offload search to a separate service, which saves valuable server resources for your site.

Why Use Elasticsearch?

WordPress’ built-in search is not optimized on sites that operate with heavy search use or complex searches. That’s because WordPress’ search works by matching full sentences in post titles, any/all search terms in post titles, and full sentence matches in post content. It relies on MySQL and does not support complex relevancy calculations or advanced filtering. More complex queries also have the risk of utilizing significant server resources.

Benchmarking Setup:

Normal Queries:
Consider a user visits your site and searches for “wine country” to find relevant events. Using normal WordPress search, the search query would execute in about 987.2ms. The equivalent Elasticsearch query executes in about 11ms, which is over 89 times faster than normal WordPress search.

Complex Queries:
Now, imagine your site also has a more complex search that includes a form with multiple taxonomies, meta fields, additional keywords, and date range search. A user comes to your site and searches for all “half marathon” events that occur between March 1, 2017 and June 30 2017 in either Arizona or California. A complex query like this, where event dates are stored in postmeta and event type is a taxonomy, would require at least eight MySQL joins and take about 1260ms to execute. The equivalent Elasticsearch query executed in about 16ms.

Apache Benchmarking:
When put to the test with Apache benchmarking using 10,000 requests and 100 concurrent users against a simple search query (e.g., “Short Ribs”), the results were:

Search Provider  

Time per Request

(mean, across all concurrent requests)

Default WP 89.708 [ms]
SearchWP/FacetWP 216.619 [ms]
Elasticsearch 88.564 [ms]

Using the complex query from above that queries posts, meta, taxonomies, and dates and benchmarking using 10,000 requests and 100 concurrent users gives the following results:

Search Provider  

Time per Request

(mean, across all concurrent requests)

Raw SQL 240.163 [ms]
Elasticsearch 102.867 [ms]

Other Reasons to Use Elasticsearch:

Conclusion

Elasticsearch is a good way to make your site performant and add enhancements to search. Whether it be facet forms, simple searches, or complex rules applied to search results, Elasticsearch will outperform most alternatives.

Exit mobile version