Skip to content

Backgrounds

How-to Guides

Technical References

Enterprise Search /

Search and multisite

If you are managing a WordPress multisite, these tips and suggestions for implementing Enterprise Search’s multisite features may be helpful.

Ensure the EP_IS_NETWORK constant is added to your vip-config.php:

define( 'EP_IS_NETWORK', true );

Subsites

Each subsite in a multisite has its own Elasticsearch index, and each may be set up differently if desired – either via a network-wide plugin or mu-plugin, or in theme code.

If you’re not implementing Enterprise Search on every multisite, or phasing it in one subsite at a time, you may need to disable sending search queries to Elasticsearch for subsites that are not ready.

However, we recommend setting up all subsites at the same time to avoid having some sites with non-functional searches.

After creating a new subsite

If you create a new subsite in a multisite, and search was already enabled for the multisite, you may need to create a search index for that site, or re-index it following a content import.

Each subsite has a separate index. Currently an index may not be created for a new subsite by default.

If the subsite has Enterprise Search enabled, then a test search can be used to check: run a search, open Search Dev Tools (available soon), and if there are no results, inspect the response JSON for an error such as “no index” or “index does not exist”.

You can also use the CLI to run a health check for the subsite, which should identify any setup issues. For example, after creating a new subsite (with a welcome post, welcome page, and comment), and adding a test post, there are inconsistencies. “welcome” is not found in a search and those items are not indexed, but the test post is indexed.

$ wp vip-search health validate-counts --url=mysubsite.example.com
Validating post count

❌  inconsistencies found when counting entity: post, type: post, index_version: 1 - (DB: 2, ES: 1, Diff: -1)
🟧 skipping, because there are no documents in ES when counting entity: post, type: page, index_version: 1

Cannot find indexable 'user', probably the feature is not enabled

If no index exists for the subsite, or the health check reveals inconsistencies, then you may create a new index as follows:

$ wp vip-search index --setup --url=mysubsite.example.com
Processed 3/3. Last Object ID: 1
Number of posts indexed: 3
Total time elapsed: 0.283
Success: Done!

$ wp vip-search health validate-counts --url=mysubsite.example.com
Validating post count

âś… no inconsistencies found when counting entity: post, type: post, index_version: 1 - (DB: 2, ES: 2, Diff: 0)
âś… no inconsistencies found when counting entity: post, type: page, index_version: 1 - (DB: 1, ES: 1, Diff: 0)

Cannot find indexable 'user', probably the feature is not enabled

Command arguments for multisite

When initiating indexes or running health checks, the following CLI arguments are helpful, or necessary.

To run a command against all subsites in the multisite: --network-wide

To run a command against just one specific subsite: --url="subsite.example.com"

For example, when enabling the Terms indexable:

$ wp vip-search activate-feature terms
$ wp vip-search put-mapping --indexables="term" --network-wide
$ wp vip-search index --indexables="term" --network-wide

Searching across subsites

To search across subsites, use the sites parameter in WP_Query. The default value is at current, but other accepted values are all, a subsite ID, and an array of subsite IDs.

For example, if we wanted to search for “test” across subsites 2 and 3:

$query = new WP_Query( array(
	's' => 'test',
	'sites' => array( 2, 3 ),
	'ep_integrate' => true
) );

Last updated: September 28, 2021