Skip to content

Instantly share code, notes, and snippets.

@jonathanstegall
Last active November 14, 2022 20:22
Show Gist options
  • Save jonathanstegall/aef855c21156eaf526aadef27d8cfb99 to your computer and use it in GitHub Desktop.
Save jonathanstegall/aef855c21156eaf526aadef27d8cfb99 to your computer and use it in GitHub Desktop.

local installation of Elasticsearch for WordPress VIP Go infrastructure

Update, 11/2022:

Apparently none of this will work with Elasticsearch versions greater than 8.0. See elastic/homebrew-tap#126 (comment). The alternative seems to be to use Docker, or since it's a big system either way might as well switch to VVV.

Previous instructions

These are basic instructions, and I'm sure could be tightened up.

  1. install elasticsearch-full (via homebrew): brew install elasticsearch-full
  2. create new index by running a PUT request to http://localhost:9200/vip-local-post-1
  3. add the following configuration values to either /wp-config.php or /wp-content/vip-config/vip-config.php (if you use vip-config.php, make sure to include the check for the local environment):
if ( 'local' === VIP_GO_ENV ) {
	/**
	 * Enable Search Dev Tools
	 *
	 */
	define( 'VIP_SEARCH_DEV_TOOLS', true ); // this should match the value you have for `WP_DEBUG` and other similar settings

	/**
	 * Values for your local Elasticsearch instance
	 *
	 */
	if ( ! defined( 'VIP_ELASTICSEARCH_ENDPOINTS' ) ) {
		define(
			'VIP_ELASTICSEARCH_ENDPOINTS',
			array(
				'http://localhost:9200/', // unless you install Elasticsearch elsewhere. The trailing slash does matter.
			)
		);
	}

	if ( ! defined( 'VIP_ELASTICSEARCH_USERNAME' ) ) {
		define( 'VIP_ELASTICSEARCH_USERNAME', 'test_user' );
	}

	if ( ! defined( 'VIP_ELASTICSEARCH_PASSWORD' ) ) {
		define( 'VIP_ELASTICSEARCH_PASSWORD', 'test_password' );
	}

	/**
	 * This is a value to generate the correct name for the local Elasticsearch index.
	 *
	 */
	if ( ! defined( 'FILES_CLIENT_SITE_ID' ) ) {
		define( 'FILES_CLIENT_SITE_ID', 'local' );
	}

	/**
	 * Errors will show in the logs without this
	 *
	 */
	if ( ! defined( 'Automattic\WP\Cron_Control\JOB_CONCURRENCY_LIMIT' ) ) {
		define( 'Automattic\WP\Cron_Control\JOB_CONCURRENCY_LIMIT', 10 );
	}
}
  1. run wp elasticpress index --setup. The --setup flag deletes and rebuilds the index.
  2. Run wp vip-search index --indexables=term --setup to index term data.
  3. Run wp vip-search activate-feature related_posts to enable related posts.
  4. run brew info elasticsearch-full and find the config directory, ex: /usr/local/etc/elasticsearch/
  5. open elasticsearch.yml and add xpack.security.enabled: false to the end
  6. run brew services restart elastic/tap/elasticsearch-full

Note: to run the index commands remotely, any wp command gets prefixed with vip @mytestsite.environmentname --

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment