Title: Jetpack Search
Author: WordPress VIP Documentation
Published: March 5, 2021
Last modified: July 16, 2024

---

 1. [WordPress on VIP](https://docs.wpvip.com/wordpress-on-vip/)
 2. [Search options](https://docs.wpvip.com/wordpress-on-vip/search-options/)
 3. Jetpack Search

#  Jetpack Search

[Jetpack Search](https://jetpack.com/support/search/) is a paid upgrade to the [Jetpack plugin](https://jetpack.com/)
that improves the search experience for WordPress sites. Jetpack Search uses [Elasticsearch](https://www.elastic.co/what-is/elasticsearch)
for indexing and searching, typically without any need for a site owner to add custom
code.

When enabled on a VIP site, Jetpack Instant Search syncs content changes to a private
cache site located within Automattic’s data centers, and uses that cached copy to
perform indexing. When search queries are performed on the VIP site, the database
query is sent to a public endpoint which only returns results for publicly available
data.

 * The first 100,000 records of a VIP site’s Jetpack Search index are free; [additional records are billable by Jetpack](https://jetpack.com/support/search/jetpack-search-product-billing/).
 * Jetpack Search is enabled per-network site on WordPress multisite environments.

## Enable Jetpack Search

To enable Jetpack Search on a production WordPress site:

 1. [Create a VIP Support request](https://wordpressvip.zendesk.com/) and specify the
    site for which Jetpack Search should be enabled.
 2. VIP Support will communicate in the support ticket when this is complete and Jetpack
    Search is ready to use.

## Enable Jetpack Search on a non-production site

Enabling Jetpack Search on a non-production WordPress site requires a VIP Support
request as well as code-enablement. After VIP Support has enabled Jetpack Search
on a non-production site, it will not work as expected until Jetpack’s search module
is force-enabled via code.

To enable Jetpack Search on a non-production WordPress site:

 1. [Create a VIP Support request](https://wordpressvip.zendesk.com/) and specify the
    site for which Jetpack Search should be enabled.
 2. VIP Support will communicate in the support ticket when this is complete and Jetpack
    Search is ready to use.
 3. Force-enable the Jetpack search module on a non-production site with the `jetpack_active_modules`
    filter. Add the following code snippet to a file in `/client-mu-plugins/` within
    the branch that deploys to the environment of the non-production site:

/client-mu-plugins/plugin-name.php

    ```lang-php
    /**
     * Force Jetpack 'search' module to be active.
     *
     * @param array $modules
     *
     * @return array
     */

    function enable_jetpack_search( $modules ) {
        $modules[] = 'search';
        return array_unique( $modules );
    }

    add_filter( 'jetpack_active_modules', 'enable_jetpack_search', 9999 );
    ```

When adding this code to a WordPress multisite, additional logic may be needed in
order for the `jetpack_active_modules` filter to only be applied to a specific network
site(s).

## Offload a front-end query to Jetpack Search

Jetpack Search is only able to handle front-end search queries (whereas Enterprise
Search is able to [offload front-end and non-standard queries](https://docs.wpvip.com/vip-search/es-enable-non-search-queries/)).
To offload an existing front-end query to the Jetpack Search index, `'es' => 'true'`
must be set for those `WP_Query` parameters. Supported queries that are sent to 
the Jetpack Search index will obtain a list of matching post IDs, and a MySQL query
will then fetch the post data.

In this code example, the `pre_get_posts` filter is used to enable offloading queries
for category pages, tag pages, and author pages to the Jetpack Search index:

    ```lang-php
    /**
    * Enable Elastic search for category, tag and author pages.
    *
    * This is optional, and only necessary if you need Jetpack search
    * for these queries
    *
    * @param $query
    */
    function vip_s__maybe_enable_es_wp_query( $query ) {

            if ( is_admin() || ! $query->is_main_query() ) {
                    return;
            }

            if ( $query->is_category() || $query->is_tag() || $query->is_author() ) {
                    $query->set( 'es', 'true' );
            }
    }

    add_action( 'pre_get_posts', 'vip_s__maybe_enable_es_wp_query' );
    ```

Last updated: July 16, 2024