简体   繁体   中英

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 ?

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.

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

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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM