Skip to content

How-to Guides

Technical References

Elasticsearch /

Elasticsearch options and debugging

Debugging Elasticsearch

The Debug Bar on VIP sites includes an Elasticsearch panel which provides details on all queries performed on the page, including the full JSON-based query sent to the index, timing data (how fast was the query, the network request, etc.), and so on. This can be incredibly useful when things aren’t working as expected.

Replacing WP_Query

We also support other advanced use cases with Elasticsearch outside of search, like offloading expensive queries.

You can use the es-wp-query plugin from Alley Interactive to offload any WP_Query lookup to Elasticsearch for the increased performance of a variety of workloads. Use of the plugin is as simple as adding ’es’ => true to your query params when building the WP_Query object.

While Elasticsearch does generally speed up most queries, there may be cases where Elasticsearch is slower. This depends on various factors like the speed of the original MySQL query (using a primary key like ID or an index), the complexity of the Elasticsearch query, cost of the network round-trip, and so on. Query times and complexity should be carefully measured before deciding to offload.

Search API

You can send fully qualified Elasticsearch queries directly to the API as well:

curl https://public-api.wordpress.com/rest/v1/sites/${SITEID_OR_URL}/search --data '{"query": { "term": { "title": "elasticsearch" } } }'

Where ${SITEID_OR_URL} should be replaced with your site’s Jetpack Site ID or the site URL. The value for the Jetpack Site ID can be found in the wp-admin of your VIP site by navigating to:

WP Admin > Tools > Site Health > Info > Jetpack

Querying multiple sites

Searching across sites is not currently supported via Jetpack Search.

Non-public content

To search for non-public content, you can make authenticated requests to the API. This can be done by filtering the Elasticsearch arguments. We recommend doing so via client-mu-plugins:

add_filter( 'jetpack_search_es_query_args', function( $es_query_args ) {
 $es_query_args['authenticated_request'] = true;

 return $es_query_args;
} );

This will make an authenticated (as your JP site) request to the Elasticsearch API, which provides access to non-public content.

We’re exploring ways to add Jetpack Search capabilities to the admin to allow for faster and more relevant searches for editorial teams. Stay tuned for more.

Mapping

More information about how content from your WordPress site is mapped to the Elasticsearch index, can be found here.

The code that handles the mapping/translation can be found here.

Last updated: January 04, 2021