Running ElasticPress in a WordPress Multisite (Network Mode)

Network Activation vs Activation Per Site Across a Network

ElasticPress can be activated in two ways when using a multisite (network mode) installation of WordPress: in the Network Admin and across the network on a per-site basis. While the first option can seem like a quick and easy way to get ElasticPress running on all the sites on your network, there are a few very significant tradeoffs from taking this approach. We’ll cover those in this article, and also provide some examples of WP-CLI commands that can make managing ElasticPress on large networks while activated on a per-site basis a lot easier.

The main advantage of Network Activation for ElasticPress is that the plugin will create a global search alias that enables you to search across sites on your network. However, this feature requires writing code to override your default search behavior and may yield undesired search results due to a lack of normalization between site data (i.e. metadata for filtering present on some, but not all, sites).

Tradeoffs of Network Activation

Language Settings

ElasticPress search is language-aware, which means that the plugin uses a language setting to tell ElasticPress.io (or Elasticsearch) how to process your content. This enables support for things like singular and plural forms of a word, past tense vs. present tense, and certain common abbreviations. If you use a single language setting in Network Mode, but have content written in multiple languages, you’ll lose the ability to process that content in a language-aware manner, and search results could be less relevant.

Other WordPress Plugins Activated Per-Site

Any plugins that are activated on a per-site basis in WordPress (rather than in the Network Admin) will not be run during the Sync process. As an example, if WooCommerce is installed on only one site within the network, any Products on that site will not be indexed, as WooCommerce will not be active during the Sync process. This is usually not the desired result, and if you happen to encounter this, you should consider activating ElasticPress on a per-site basis.

Activating ElasticPress on Multiple Sites

One of the main reasons for activating the plugin in Network Mode is that it automatically activates the plugin on all sites across the network. If you’d like to accomplish this, but avoid the pitfalls of Network Mode activation, you can use WP-CLI commands.

Activate via WP-CLI

First, activate the plugin across all sites on your network:

wp site list --field=url | xargs -n1 -I % wp --url=% plugin activate elasticpress

Next, you’ll want to index all the sites one by one:

wp site list --field=url | xargs -n1 -I % wp --url=% elasticpress sync --setup --yes

Set a single ElasticPress.io Subscription or Elasticsearch Endpoint via wp-config.php

To set all your sites to use a single ElasticPress.io or Elasticsearch endpoint, you can add credentials in wp-config.php using the following defines:

define( 'EP_CREDENTIALS', 'demo:icanhazpassword' );
define( 'EP_HOST', 'https://clusters.elasticpress.io:9999/' );

EP_CREDENTIALS are your ElasticPress.io Subscription ID and Subscription Token separated by a colon. EP_HOST is the value of your Subscription URL. If you are running a self-hosted instance, these values will correspond to your Elasticsearch endpoint and security credentials.