Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elasticsearch: can't connect via curl, weird inconsistent behavior

I'm running Elasticsearch 1.3.4, freshly installed on Mac OS X 10.10 via Homebrew:

$ brew install elasticsearch
$ elasticsearch

Running http://localhost:9200/_cluster/state in the browser succeeds:

{
  "cluster_name": "elasticsearch_jbrukh",
  "version": 2,
  "master_node": "q6Jzcza_RwaVvc_1u95O1Q",
  "blocks": {},
  "nodes": {
    "q6Jzcza_RwaVvc_1u95O1Q": {
      "name": "Ethan Edwards",
      "transport_address": "inet[/127.0.0.1:9300]",
      "attributes": {}
    }
  },
  "metadata": {
    "templates": {},
    "indices": {}
  },
  "routing_table": {
    "indices": {}
  },
  "routing_nodes": {
    "unassigned": [],
    "nodes": {
      "q6Jzcza_RwaVvc_1u95O1Q": []
    }
  },
  "allocations": []
}

However, the following curl command fails:

$ curl -XGET "http://localhost:9200/_cluster/state"
curl: (7) Failed to connect to localhost port 9200: Connection refused

Moreover, the curl command succeeds intermittently, but only AFTER that URL is hit from the browser, then it works one time and then starts to fail again with the above error.

How can I fix that ?

like image 600
Jake Avatar asked Jan 14 '15 22:01

Jake


2 Answers

As I answered before on a similar question here. On my Mac OS X, I use 127.0.0.1:9200/ instead of http://localhost:9200/ cause I had the same problem.

I think that when you use the command the terminal replaces the localhost by it's IPv6 address and I'm not sure that curl supports that.

Please check and let me know.

like image 131
eliasah Avatar answered Jan 03 '23 14:01

eliasah


I had the same problem (OS X 10.10 & ES 1.3.4).

Quick solution is to force curl to use IPv4 with --ipv4

curl --ipv4 -XGET "http://localhost:9200/_cluster/state"

(at least for me it worked)

Permanent solution is to edit /etc/hosts and comment out this line

#fe80::1%lo0    localhost
like image 23
Igor Rjabinin Avatar answered Jan 03 '23 16:01

Igor Rjabinin