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

curlelasticsearch

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 ?

Best Answer

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.

Related Topic