No Connection On Localhost To Elasticsearch On OSX

tl;dr Comment a line in /etc/hosts.

After the update to OSX 10.10 Yosemite, I also updated everything I've installed with brew. Sadly after this update, I couldnt get Elasticsearch to accept connections again. It started normally without any error but curl showed my the very lovely connection refused error:

$ curl -i localhost:9200
curl: (7) Failed to connect to localhost port 9200: Connection refused

Or with more verbosity:

$ curl -i -v localhost:9200
* Rebuilt URL to: localhost:9200/
* Hostname was NOT found in DNS cache
*   Trying ::1...
* connect to ::1 port 9200 failed: Connection refused
*   Trying fe80::1...
* connect to fe80::1 port 9200 failed: Connection refused
* Failed to connect to localhost port 9200: Connection refused
* Closing connection 0
curl: (7) Failed to connect to localhost port 9200: Connection refused

First I started to search in Elasticsearch configs et al but found the error somewhere on Stackoverflow. It seems like OSX is doing something weird when upgrading to Yosemite. So the easy fix is to disable the IPv6 entry in your /etc/hosts. Just comment the following line in this file:

fe80::1%lo0    localhost

After this Elasticsearch should work again normally.

$ curl -i localhost:9200
HTTP/1.1 200 OK
Content-Type: application/json; charset=UTF-8
Content-Length: 335

{
  "status" : 200,
  "name" : "War",
  "cluster_name" : "elasticsearch_ben",
  "version" : {
    "number" : "1.4.2",
    "build_hash" : "927caff6f05403e936c20bf4529f144f0c89fd8c",
    "build_timestamp" : "2014-12-16T14:11:12Z",
    "build_snapshot" : false,
    "lucene_version" : "4.10.2"
  },
  "tagline" : "You Know, for Search"
}