alleyinteractive / searchpress

Elasticsearch integration for WordPress.
84 stars 12 forks source link
elasticsearch wordpress wordpress-plugin

SearchPress

SearchPress

Elasticsearch integration for WordPress.

Release Information

Each stable release gets tagged and you can download releases from GitHub. master points to the latest stable release at any given time.

Pre-Release Versions

Pre-release development happens against release/<version> branches. Once a release is ready-to-ship, it is merged into master and tagged.

Backwards Compatibility & Breaking Changes

We try to maintain backwards compatibility as much as possible. It's possible that releases will need to contain breaking changes from time to time, especially as Elasticsearch itself is a constantly changing product. Breaking changes will be detailed in release notes.

SearchPress has a thorough battery of unit and integration tests to help add compatibility with each new Elasticsearch release, without compromising compatibility with older releases.

Prerequisites

Setup

  1. Upload to the /wp-content/plugins/ directory
  2. Activate the plugin through the 'Plugins' menu in WordPress
  3. You'll be prompted to add your Elasticsearch endpoint and to index your posts
    • SearchPress provides a WP-CLI command for faster indexing on large sites
  4. Once indexing is complete, you're good to go!

Indexing Post Meta

In early versions of SearchPress, SearchPress would index almost all post meta with the post. Starting in the 0.4 release, SearchPress only indexes the post meta that it is explicitly told to index. Further, it only indexes post meta in the data types that a site's developer plans to use. The principal reason behind this change is performance, and to prevent "mappings explosion".

Data type casting will only be attempted for a key if the opt-in callback specifies that type for the key in question (see example below for the full list of possible types). However, the data type will still only be indexed if the type casting is successful. For example, attempting to index the meta value "WordPress" as a long would fail, since it is not a numeric value. This failure is silent, for better or worse, but type casting is overall quite forgiving.

If a meta key is allowed to be indexed, the meta value will always be indexed as an unanalyzed string (post_meta.*.raw) and that type need not be specified. This is primarily for compatibility with ES_WP_Query, which depends on that key in EXISTS queries, among others.

How to index post meta

add_filter(
    'sp_post_allowed_meta',
    function( $allowed_meta ) {
        // Tell SearchPress to index 'some_meta_key' post meta when encountered.
        $allowed_meta['some_meta_key'] = [
            'value',    // Index as an analyzed string.
            'boolean',  // Index as a boolean value.
            'long',     // Index as a "long" (integer).
            'double',   // Index as a "double" (floating point number).
            'date',     // Index as a GMT date-only value in the format Y-m-d.
            'datetime', // Index as a GMT datetime value in the format Y-m-d H:i:s.
            'time',     // Index as a GMT time-only value in the format H:i:s.
        ];
        return $allowed_meta;
    }
);

Changelog

0.5.1

0.5

0.4.3

0.4.2

0.4.1

0.4

0.3

0.2

0.1