Elasticsearch:无法通过 curl 连接,奇怪的不一致行为

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

我是 运行 Elasticsearch 1.3.4,通过 Homebrew 新安装在 Mac OS X 10.10 上:

$ brew install elasticsearch
$ elasticsearch

运行 http://localhost:9200/_cluster/state 在浏览器中成功:

{
  "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": []
}

但是,以下 curl 命令失败:

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

此外,curl 命令间歇性地成功,但只有在从浏览器中点击 URL 之后,它才工作一次,然后再次开始失败并出现上述错误。

我该如何解决?

正如我之前回答过的类似问题here. On my Mac OS X, I use 127.0.0.1:9200/ instead of http://localhost:9200/ 因为我遇到了同样的问题。

我认为当您使用该命令时,终端会用它的 IPv6 地址替换本地主机,我不确定 curl 是否支持。

请检查并告诉我。

我有同样的问题(OS X 10.10 & ES 1.3.4)。

快速解决方案是强制 curl 使用 IPv4 --ipv4

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

(至少对我有用)

永久解决方案是编辑 /etc/hosts 并注释掉这一行

#fe80::1%lo0    localhost

我遇到了类似的问题,但似乎是相反的。

Elasticsearch 似乎正在侦听 ipv6 而不是 ipv4。为了迫使我的客户端与其对话(在我的例子中是节点 js 驱动程序 [1]),我发现 ipv6 localhost 的符号是命中它的唯一方法:http://[::1]:9200.

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