Jake
Jake

Reputation: 15217

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 ?

Upvotes: 5

Views: 16929

Answers (3)

Ben Gourley
Ben Gourley

Reputation: 129

I'm getting a similar issue issue, but seems to be the other way around.

Elasticsearch appears to be listening on ipv6 but not ipv4. In order to force my client to speak to it (in my case the node js driver [1]), I found that the notation for ipv6 localhost is the only way to hit it: http://[::1]:9200.

[1] https://github.com/elastic/elasticsearch-js/

Upvotes: 0

Igor Rjabinin
Igor Rjabinin

Reputation: 891

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

Upvotes: 8

eliasah
eliasah

Reputation: 40370

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.

Upvotes: 21

Related Questions