You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Elasticsearch跨集群重索引报unknown_host_exception问题求助

问题原因&解决办法

嘿,这个问题我之前排查过类似的!你遇到的unknown_host_exception根本原因是Elasticsearch解析远程主机地址的逻辑和curl不一样:

你把完整的路径/api/elasticsearch和主机地址拼在一起塞给了remote.host参数,但这个字段只负责识别主机名+端口(http默认80、https默认443可以省略),后面的路径部分它会直接当成主机名的一部分去DNS解析,自然找不到叫api.example.com/api/elasticsearch的主机,所以抛出了“名称或服务未知”的错误。

而你用curl http://api.example.com:80/api/elasticsearch/_cat/indices?v能成功,是因为curl会把整个URL拆成主机、端口、路径三部分去处理,Nginx也能正确匹配到对应的代理路径,但Elasticsearch的_reindex模块不支持这种写法。


修正后的重索引命令

把路径部分单独抽出来,用remote下的path_prefix参数指定,正确的命令如下:

curl -X POST http://elasticsearch:9200/_reindex -d '{ 
  "source": { 
    "remote": { 
      "host": "http://api.example.com",
      "path_prefix": "/api/elasticsearch"
    }, 
    "index": "alias_name" 
  }, 
  "dest": { 
    "index": "index_name" 
  } 
}'

如果你的远程服务必须显式指定80端口,也可以把host写成"http://api.example.com:80",不过http协议默认就是80端口,不写也完全没问题。


额外要检查的配置

别忘记确认本地Elasticsearch已经允许这个远程主机的重索引请求:
打开elasticsearch.yml配置文件,检查是否存在以下配置(如果没有就加上):

reindex.remote.whitelist: "api.example.com:80"

如果省略了端口,也可以写成reindex.remote.whitelist: "api.example.com"。修改后需要重启Elasticsearch才能生效。

内容的提问来源于stack exchange,提问作者Khmtrav

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 03:46:12