Blog Insights
Searching Multiple WordPress Sites with Elasticsearch

Recently, we worked with an organization that maintained two separate WordPress sites. One site was their organization’s “main,” public-facing site, which housed content about its leadership, work and day-to-day activities. The other was a less formal blog, which housed timely commentary and invited reader feedback through comments.

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.

Are you ready to create impact?

We'd love to connect and discuss your next project.