Accessing Elasticsearch Remotely through Vagrant

I’ve been doing a lot of work on 10up’s ElasticPress project over the last year including implementation on various sites as well as work on the plugin itself. After stepping a way for a bit though I found a problem yesterday morning when while working on implementation for one of our larger clients.

The Issue

Normally I develop entirely on Primary Vagrant. This means that in order to connect directly to Elasticsearch with a tool such as Paw or Postman I need to be able to connect to the box. Normally I simply input the url of the development site I work with and point it to port 9200 and I’m off and running. That wasn’t the case this morning. Yesterday morning, on a new install of the latest Elasticsearch and without any firewall or other software running it simply couldn’t connect.

Some Caveats

Truth be told I hadn’t used a REST client like Paw for a while as I hadn’t working any ElasticPress implementations since before Elasticsearch 2.0. There lies the problem. Somewhere in the 2.0 line the default behaviour of allowing networking was turned off and the service was bound only to localhost. This is a change from previous versions.

The Fix

Fortunately it was a pretty simple fix. Here’s what you can do if you need to make Elasticsearch available on your own Primary Vagrant, VVV or other Vagrant development box.

1.) Edit elasticsearch.yml
sudo vi /etc/elasticsearch/elasticsearch.yml

2.) Replace the binding address with 0.0.0.0
Somewhere around line 54 (if you’re on Ubuntu with Elasticsearch 2.3) you’ll find # network.host: …. Replace the line with the following (make sure to remove the # symbol):

network.host: 0.0.0.0

3.) Restart Elasticsearch
sudo service elasticsearch restart

Now, you should be able to query Elasticsearch directly from your host machine with a client like Paw or anything else you might need to get at it with.

About Chris Wiegman

Chris is a Senior Web Engineer for 10up where he works on solutions for clients both large and small. In past roles he has served as a teacher, blogger, manager and even an airline captain. He resides in Florida with his wife Joy and their four-legged children.

Find Chris on Facebook, GitHub, WordPress.org, and Twitter.

Leave a Reply

Your email address will not be published. Required fields are marked *

  
Please enter an e-mail address