How to use Elasticsearch with ElasticPress

    on Managed WordPress and Managed WooCommerce Sites

    The default WordPress search can be very slow and if you’re trying to query a number of posts can take forever to return any relevant information. Having a fast and relevant search on your site will help visitors and customers find what they are looking for.

    One of the better options to improve site search on a WordPress site, as well as a site running WooCommerce, is to use Elasticsearch with the ElasticPress plugin.

    You can install the ElasticPress plugin from wp-admin in Plugins > Add New and then search for elasticsearch and then install and activate the plugin.

    In order to be able to use the ElasticPress plugin to power your site search, you will need to enable the ElasticSearch container in the portal of your site.

    The endpoint (host) and port can be found from the containers tab in the portal. That info will need to be added to the site’s wp-config.php file.

    Example of the Elasticsearch host info and port you will need the change the host URL and the point based on the information that shows in the portal.

    /** ElasticPress */

    define( 'EP_HOST', 'http://cg-1181-elasticsearch.us-midwest-1.nxcli.net:27059' );

    Site content can be indexed from the ElasticPress settings in wp-admin. WooCommerce settings will be defaulted enabled to index WooCommerce content on the site. 

    Having a number of product posts or posts will take a while to index, which is why on those sites it is worth running the index from WP-CLI command.

    Example WP-CLI commands to run.

    To install and activate the ElasticPress plugin run;

    wp plugin install elasticpress --activate

    To index and setup ElasticPress plugin run;

    wp elasticpress index --setup

    Once all of the content has been indexed this is what you will see in the terminal.

    Number of posts indexed: 15463

    Total time elapsed: 465.652

    Success: Done!

    To index and setup ElasticPress plugin to include posts and products;

    wp elasticpress index --setup --post-type="products,posts"

    To delete the existing index in Elasticsearch from the site run;

    wp elasticpress delete-index

    To get the status of ElasticPress run;

    wp elasticpress status

    To get the stats of ElasticPress run;

    wp elasticpress stats

    Which will return a similar response to this.

    [a134d331@cloudhost-139961 public_html]$ wp elasticpress stats

    ====== Stats for: 3b1012aedenxclinet-post-1 ======

    Documents: 15463

    Index Size: 290.31 MB

    Index Size (including replicas): 290.31 MB

    ====== End Stats ======

    Also from within wp-admin on your site, you can see the index health of Elasticsearch directly in ElasticPress.

    ElasticPress > Index Health

    The autosuggest feature in ElasticPress due to how the endpoint needs to work may not work on the site.

    An Elasticsearch container used with ElasticPress will improve the search on your site and well as help customers and visitors be able to find what they are looking for.

    For 24-hour assistance any day of the year, contact our support team by email or through your Client Portal.

    Was this article helpful?

    Send feedback

    Can’t find what you’re looking for?

    Our award-winning customer care team is here for you.

    Contact Support