{"record":{"id":"f88829c9c0127068","repo":"zhisheng17/flink-learning","slug":"invalid-elasticsearch-hosts-format-f88829","errorCode":null,"errorMessage":"invalid elasticsearch hosts format","messagePattern":"invalid elasticsearch hosts format","errorType":"exception","errorClass":"MalformedURLException","httpStatus":null,"severity":"error","filePath":"flink-learning-monitor/flink-learning-monitor-log/src/main/java/com/zhisheng/log/utils/ESSinkUtil.java","lineNumber":61,"sourceCode":"     * 解析配置文件的 es hosts\n     *\n     * @param hosts\n     * @return\n     * @throws MalformedURLException\n     */\n    public static List<HttpHost> getEsAddresses(String hosts) throws MalformedURLException {\n        String[] hostList = hosts.split(\",\");\n        List<HttpHost> addresses = new ArrayList<>();\n        for (String host : hostList) {\n            if (host.startsWith(\"http\")) {\n                URL url = new URL(host);\n                addresses.add(new HttpHost(url.getHost(), url.getPort()));\n            } else {\n                String[] parts = host.split(\":\", 2);\n                if (parts.length > 1) {\n                    addresses.add(new HttpHost(parts[0], Integer.parseInt(parts[1])));\n                } else {\n                    throw new MalformedURLException(\"invalid elasticsearch hosts format\");\n                }\n            }\n        }\n        return addresses;\n    }\n}\n","sourceCodeStart":43,"sourceCodeEnd":68,"githubUrl":"https://github.com/zhisheng17/flink-learning/blob/d731cee7618021be56d132cc925102ffff8d75e6/flink-learning-monitor/flink-learning-monitor-log/src/main/java/com/zhisheng/log/utils/ESSinkUtil.java#L43-L68","documentation":"ESSinkUtil.getEsAddresses parses a host string into HttpHost addresses. When the host entry contains no ':' delimiter (so no host:port pair can be extracted) it throws MalformedURLException 'invalid elasticsearch hosts format'. The parser expects entries like host:9200 or http://host:9200.","triggerScenarios":"Passing an elasticsearch hosts config value whose items lack a port — e.g. 'localhost' alone, empty items from a trailing comma, or a malformed URL that URL parsing rejected earlier.","commonSituations":"Configuring es.hosts=localhost without :9200, whitespace or empty segments in a comma-separated list, IPv6 addresses with colons confusing the split, or a typo dropping the port.","solutions":["Include the port in every host entry, e.g. localhost:9200 or node1:9200,node2:9200.","Remove empty/duplicate separators (trailing commas, spaces) from the hosts list.","If the scheme is included, keep it well-formed (http://host:9200)."],"exampleFix":"// before\nes.hosts = localhost,es1\n// after\nes.hosts = localhost:9200,es1:9200","handlingStrategy":"validation","validationCode":"for (String host : hostsCsv.split(\",\")) {\n    String h = host.trim();\n    if (h.isEmpty() || !h.matches(\"(https?://)?[^:]+:\\\\d+\")) {\n        throw new IllegalArgumentException(\"ES host must be host:port, got: '\" + h + \"'\");\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    List<HttpHost> addrs = ESSinkUtil.getEsAddresses(paramTool.get(\"es.hosts\"));\n} catch (MalformedURLException e) {\n    LOG.error(\"Bad elasticsearch hosts format: {}\", e.getMessage());\n}","preventionTips":["Always specify host:port for every Elasticsearch entry.","Trim and drop empty segments from comma-separated host lists.","Document default port 9200 in your config templates."],"tags":["elasticsearch","configuration","url-parsing"],"backgroundTag":"invalid-url-format","analyzedSha":"d731cee7618021be56d132cc925102ffff8d75e6","analyzedAt":"2026-09-06T05:35:08.496Z","contentChangedAt":"2026-09-06T05:35:08.496Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}