So our WooCommerce setup ran out of steam. With approx. 28k products and 92k variants both shop frontend and products area in backend were too slow for production use.
Elastic Search to the rescue! Thanks to the fine folks at 10up and their absolutely great plugin ElasticPress, it is quite manageable for anyone to use an Elastic Search server to deliver product data. Here’s a quick overview on how that’s done, and which issues we stumbled across during the process.
Setup ElasticPress plugin
The plugin installation is easy. Install it via plugin edit screen, activate, done.
Just to be sure, we are talking about this plugin: https://wordpress.org/plugins/elasticpress/
Connect the shop to your Elastic Search instance
The easiest way is to connect your site to an instance on elasticpress.io. It’s an Elastic Search hosting service, provided by, well you guess it, the ElasticPress team.
It is also possible to use any other Elastic server instance. Another hosted option is elastic.co, from the makers of Elastic Search. As written earlier, we decided for this experiment just to setup an Elastic server on our own. For a production setup, it is probably a good idea to go for a hosted service if you don’t want to take care about securing and maintaining the Elastic database server or cluster.
More information on how the connection works is provided by the plugin authors, here is a good starting point to read the docs: https://github.com/10up/ElasticPress
Setup ElasticPress for queries in the backend
When lots of posts are in the database, some pages in the WordPress admin area will get slow. So it is a good idea to also use elastic queries in the backend.
After setting up ElasticPress, our backend queries were not automatically using elastic. To enable that, we had to enable the feature “Protected Content”. Draft and private posts are not submitted to elastic when this feature is disabled. Since the backend queries may include these types of posts, the queries aren’t routed to elastic when “Protected Content” is disabled. Hint: After enabling “Protected Content” you have to reindex the elastic index via “Delete All Data and Sync” in the Sync menu.
… But still: Very slow edit product pages 🤯
Now the backend was elastic-supercharged, but still, the edit product pages needed about 20 seconds to load! Same as before! At that point, we had approximately 28k products, with 100k variants in the database.
Denis found out the reason: “I checked in query monitor where wpdb query is executed, found that place in WP Core, understood that it’s rendering custom fields metabox and removed it for products.”
After that, product edit page loads and saves just at normal speed. Awesome!
Here’s a code snippet which removes the metabox:
/**
* Remove Custom Fields meta box
*/
function elbytes_remove_post_custom_fields_metabox() {
remove_meta_box( 'postcustom' , 'product' , 'normal' );
}
add_action( 'add_meta_boxes' , 'elbytes_remove_post_custom_fields_metabox', 999 );