--- title: "主机未在设置中列入白名单 - 如何解决此Elasticsearch异常" date: 2026-02-02 lastmod: 2026-02-02 description: "当尝试连接的Elasticsearch节点未包含在设置中的允许主机列表(白名单)时,会出现此错误。这是一个安全措施,用于防止未经授权的访问。" tags: ["白名单", "安全设置", "异常处理", "主机访问"] summary: " 版本: 7-7.15 简而言之,当您尝试连接的Elasticsearch节点未包含在Elasticsearch设置的允许主机列表(白名单)中时,会出现此错误。这是防止未经授权访问的安全措施。要解决此问题,您可以将主机添加到Elasticsearch设置的白名单中,或者如果不需要则禁用白名单检查。但是,禁用白名单检查可能会使您的Elasticsearch面临潜在的安全风险。始终确保您的Elasticsearch得到适当的安全保护。 日志上下文 # 日志 “host [” + host + “] is not whitelisted in setting [” 类名称是 HttpClient.java。 我们从Elasticsearch源代码中提取了以下内容,供那些寻求深入上下文的人使用: HttpContext context) throws ProtocolException { boolean isRedirected = super.isRedirected(request; response; context); if (isRedirected) { String host = response.getHeaders("Location")[0].getValue(); if (isWhitelisted(host) == false) { throw new ElasticsearchException("host [" + host + "] is not whitelisted in setting [" + HttpSettings.HOSTS_WHITELIST.getKey() + "]; will not redirect"); } } return isRedirected; " --- > **版本:** 7-7.15 简而言之,当您尝试连接的Elasticsearch节点未包含在Elasticsearch设置的允许主机列表(白名单)中时,会出现此错误。这是防止未经授权访问的安全措施。要解决此问题,您可以将主机添加到Elasticsearch设置的白名单中,或者如果不需要则禁用白名单检查。但是,禁用白名单检查可能会使您的Elasticsearch面临潜在的安全风险。始终确保您的Elasticsearch得到适当的安全保护。 日志上下文 ----------- 日志 "host [" + host + "] is not whitelisted in setting [" 类名称是 [HttpClient.java。](https://www.geeksforgeeks.org/java-lang-class-class-java-set-1/) 我们从Elasticsearch源代码中提取了以下内容,供那些寻求深入上下文的人使用: ```java HttpContext context) throws ProtocolException { boolean isRedirected = super.isRedirected(request; response; context); if (isRedirected) { String host = response.getHeaders("Location")[0].getValue(); if (isWhitelisted(host) == false) { throw new ElasticsearchException("host [" + host + "] is not whitelisted in setting [" + HttpSettings.HOSTS_WHITELIST.getKey() + "]; will not redirect"); } } return isRedirected; ```