Blog Insights
Searching Multiple WordPress Sites with Elasticsearch
The organization came to Forum One seeking to unify the site’s search results. They wanted users to be able to search the organizational site and get results from both that site and the blog. The main site was already using Elasticsearch as a search backend, integrated with WordPress using the ElasticPress plugin.
Our first thought was to combine the site into a multi-site architecture, as ElasticPress supports unified search for multiple sites that way. It turned out there was an easier solution. We allowed each site access to the Elasticsearch server. Then we used the “ep_index_name” filter to connect both sites to the same Elasticsearch index, which we defined as the same constant in the wp-config.php files of both sites.
The filter implementation looked like this in the theme’s functions.php file:
function f1_change_es_host($index_name) {
return ES_INDEX;
}
add_filter('ep_index_name', 'f1_change_es_host');
It became a matter of running the indexer on both sites. Once that was completed, users could perform keyword searches on either site and receive results from both.