How to use Elasticsearch with WordPress in a Local Environment

Elasticsearch speeds up your WordPress site dramatically by replacing the default search “WP_Query” with the Elasticsearch system allowing visitors to search for More, and get Better results much Faster.

If you have not read our article "Why you should be using...." then [click here]( "Why Elasticsearch") and see why you need Elasticsearch powering your site.

Before you dive headfirst into installing Elasticsearch on your server (check out our guide "How to install Elasticsearch"); you might want to first try it out in a local development environment.

There are lots of different ways to get a local WordPress install for development up and running. This guide will focus on setting up Elasticsearch with the most common ones; Vagrant and Docker.

The path via Vagrant

If your current WordPress development environment is using Vagrant, then there are a few things you need to do before powering your site with Elasticsearch.

Install ElasticSearch Service

The easiest way to get ElasticSearch running with Vagrant is to make a new Vagrant Box and run it as a separate VM. Luckily, all the heavy lifting is made easy using a VagrantFile created by Matthew McAchran on GitHub. All you need to do is clone the ["Elasticsearch Vagrant box" GitHub Repo]( and let it do the work.  Open a new Terminal Window or Command Prompt and navigate to a folder for your new Vagrant Box (the location of this is up to you).

cd /usr/mozr/vagrant/boxes
git clone

Now  go into the directory and tell Vagrant to spin up a new VM using the VagrantFile in there.

cd elasticsearch-vagrant
vagrant up

Running this takes a while as Vagrant needs to download a new image then set up a new machine.

IMPORTANT NOTE: This spins up a new VM with the IP Address of; if you already have a VM with this IP or you want to use another IP instead, edit the "Vagrantfile" in the `elasticsearch-vagrant` folder and change the line with `box_ip = ''` to a suitable IP Address.

Once Vagrant has finished installing the new ElasticSearch Box, you should test it to make sure it is functioning correctly.  SSH into the server and send it a test command:

vagrant ssh
curl -X GET 'http://localhost:9200'

If ElasticSearch is installed you will get a response like this:


 "name" : "Burner",

 "cluster_name" : "elasticsearch",

 "cluster_uuid" : "kD2YBPEUTqCw_CM9inBFQQ",

 "version" : {

   "number" : "2.4.1",

   "build_hash" : "c67dc32e24162035d18d6fe1e952c4cbcbe79d16",

   "build_timestamp" : "2016-09-27T18:57:55Z",

   "build_snapshot" : false,

   "lucene_version" : "5.5.2"


 "tagline" : "You Know, for Search"


The path via Docker

Getting Elasticsearch working in a local Docker environment is super easy. The Elasticsearch team have created a Docker image ready to use.

Setting up the Docker Image

Wherever you have Docker installed, just run the following command to retrieve the image:

docker pull

Once the image has finished downloading, you can bring up the new Docker container with the following command:

docker run -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node"

If you get an error message about insufficient memory, then try setting the memory allocation for Elasticsearch to a lower amount. You can do this by modifying the command as follows:

docker run -p 9200:9200 -p 9300:9300 -e ES_JAVA_OPTS="-Xms512m -Xmx512m" -e "discovery.type=single-node" docker.elast

This Docker image comes with [X-Pack]( pre-installed and a trial license for 30 days. X-Pack adds security features to Elasticsearch, but this means you need to authenticate with the server. The default username is 'elastic' with a password of 'changeme'. For more information on the X-Pack Security feature check out [this page](

Installing the ElasticPress Plugin

Now you need to install the [ElasticPress Plugin"]( "ElasticPress on") made by the folks over at 10up. You can do this by downloading the plugin then installing it using your WordPress dashboard, or by using WP-CLI, the WordPress Command Line Interface system.

You can instruct WP-CLI to install the ElasticPress plugin directly from and follow the progress.

wp plugin install elasticpress --activate

Installing elasticpress (2.4)

Downloading install package from

Using cached file '/home/vagrant/.wp-cli/cache/plugin/'...

Unpacking the package...

Installing the plugin...

Plugin installed successfully.

Activating 'elasticpress'...

Plugin 'elasticpress' activated.

Success: Installed 1 of 1 plugins.


Connecting ElasticSearch with the ElasticPress Plugin

Now that you have the ElasticPress plugin installed on your WordPress site, and have ElasticSearch running; you need to do the final bit of configuration.

Firstly we need to tell your WordPress install where the ElasticSearch server is. You need to find the IP address of your Elasticsearch Docker Container.

You can do this by adding the following line to your wp-config file:

For Vagrant

‘EP_HOST’, ‘’

For Docker

‘EP_HOST’, ‘http://DOCKER_IP:9200/’

Alternatively, you can do it through the WordPress Dashboard.

Login to your WordPress Dashboard, then select "ElasticPress" from the navigation menu

Click the white "Set Up" Button

Enter the ElasticServer address (For Vagrant: - For Docker: http://DOCKER_IP:9200/) into the box and click blue "Save Changes" button

Now all that is left is to sync the current WordPress database to Elasticsearch. Luckily the plugin can do all this for us automatically.

Just click the Sync Icon in the top right hand corner, and the plugin does the rest.

If you want to use the AutoSuggest feature of Elasticsearch, you must either give the search input fields a type equal to “search” or give them a CSS class of  “search-field” or “ep-autosuggest.”

That is it, Elasticsearch is now installed, synchronized with your WordPress install and powering your searches!