How can I search across multiple sites in a multi-site?

For multi-site (aka Network Mode) installations of WordPress, ElasticPress offers the custom site__in WP_Query parameter. This parameter lets you specify a number of different options to search across one or multiple sites in the network.

You can read the details about the site__in parameter here. The site__in parameter takes a few different options, including currentall, and an array of Site IDs like [ 2, 3 ].

For example, if you want to search just the current site, simply add the following to your WP_Query:

PHP
new WP_Query(
	[
		's'        => 'search phrase',
		'site__in' => 'current',
	]
);

Want results from all sites on the network? Just adjust the query to change site__in to all:

PHP
new WP_Query(
	[
		's'        => 'search phrase',
		'site__in' => 'all',
	]
);

And if you need results from just a few of the sites on your network, you can specify them using their numeric Site IDs:

PHP
new WP_Query(
	[
		's'        => 'search phrase',
		'site__in' => [ 2, 4 ],
	]
);