Skip to main content
Last Reviewed: 2026-02-10

Elasticsearch Query Optimization

Instructions for optimizing queries with the ElasticPress plugin on your Pantheon WordPress site.


Information:
Beta support for Elasticsearch

This documentation describes support for Elasticsearch that is under active development and is available to customers who are participating in our Beta program.

One of the most powerful aspects of Elasticsearch on Pantheon is its ability to offload WP_Query requests from your database. The ElasticPress plugin integrates with WordPress at the query level, routing eligible queries to Elasticsearch instead of MySQL.

How ElasticPress Integrates with WP_Query

When ElasticPress is active and configured, it automatically routes WordPress search queries (any WP_Query with an s parameter) through Elasticsearch instead of MySQL. For non-search queries — archives, custom loops, filtered post lists — you can opt in to Elasticsearch by setting the ep_integrate parameter to true

The ep_integrate Parameter

For custom queries where you want to explicitly control Elasticsearch integration, ElasticPress provides the ep_integrate parameter. You can add this to any WP_Query or get_posts() call:

You can also use ep_integrate to explicitly exclude a query from Elasticsearch:

For more general use integration with query blocks or archive pages, you can use the ep_integrate parameter with the pre_get_posts action:

When to Use ep_integrate

Use ep_integrate => true for queries that are:

  • Performance-critical and would benefit from faster response times
  • Search-related or involve complex filtering
  • Serving high-traffic pages where database load is a concern

In many cases, ep_integrate may be slower for simple queries that the database can handle efficiently, especially if the content is not yet indexed in Elasticsearch. For these cases, you can use ep_integrate => false or not add the ep_integrate parameter to ensure the query runs against the database instead.

Keeping Your Index Current

After making significant content changes, run an index sync to ensure Elasticsearch has the latest data. You can trigger a sync from the ElasticPress dashboard in WordPress admin or via WP-CLI:

For large sites, consider running the sync with the --per-page flag to manage memory usage: