{"record":{"id":"6446847120d08cfb","repo":"getredash/redash","slug":"connection-refused","errorCode":null,"errorMessage":"Connection refused","messagePattern":"Connection refused","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"redash/query_runner/elasticsearch.py","lineNumber":333,"sourceCode":"                    add_column_if_needed(mappings, column, column, result_columns, result_columns_index)\n\n                    value = h[column_name][column]\n                    row[column] = value[0] if isinstance(value, list) and len(value) == 1 else value\n\n                result_rows.append(row)\n        else:\n            raise Exception(\"Redash failed to parse the results it got from Elasticsearch.\")\n\n    def test_connection(self):\n        try:\n            r = requests.get(\"{0}/_cluster/health\".format(self.server_url), auth=self.auth)\n            r.raise_for_status()\n        except requests.HTTPError as e:\n            logger.exception(e)\n            raise Exception(\"Failed to execute query. Return Code: {0}   Reason: {1}\".format(r.status_code, r.text))\n        except requests.exceptions.RequestException as e:\n            logger.exception(e)\n            raise Exception(\"Connection refused\")\n\n\nclass Kibana(BaseElasticSearch):\n    @classmethod\n    def enabled(cls):\n        return True\n\n    def _execute_simple_query(self, url, auth, _from, mappings, result_fields, result_columns, result_rows):\n        url += \"&from={0}\".format(_from)\n        r = requests.get(url, auth=self.auth)\n        r.raise_for_status()\n\n        raw_result = r.json()\n\n        self._parse_results(mappings, result_fields, raw_result, result_columns, result_rows)\n\n        total = raw_result[\"hits\"][\"total\"]\n        result_size = len(raw_result[\"hits\"][\"hits\"])","sourceCodeStart":315,"sourceCodeEnd":351,"githubUrl":"https://github.com/getredash/redash/blob/ca79fe988d81cdac9675b412f3dfcab107bc1fbc/redash/query_runner/elasticsearch.py#L315-L351","documentation":"Raised by the legacy ElasticSearch/Kibana query runner's test_connection when a requests.exceptions.RequestException occurs — i.e. the HTTP request never completed (DNS failure, refused socket, timeout, SSL error). It maps every low-level transport failure to the generic message 'Connection refused', which can be misleading (e.g. a timeout also produces it).","triggerScenarios":"Calling test_connection against an Elasticsearch/Kibana URL whose host/port is unreachable, wrong port, firewall blocking the connection, bad hostname, or HTTPS/SSL mismatch. Any RequestException that is not an HTTPError triggers it.","commonSituations":"Wrong URL/port in the Redash data source settings, Elasticsearch behind a proxy or requiring TLS, cluster down during setup verification, typo in host name.","solutions":["Verify the Elasticsearch/Kibana server URL and port (default 9200/5601) in the data source configuration and that the server is running","Test reachability from the Redash host: curl -v <url> or telnet host port; check firewall/security groups","If the server uses HTTPS or a self-signed cert, correct the URL scheme and certificate settings","Prefer the elasticsearch2 query runner (newer) which gives more precise errors"],"exampleFix":"// before\nurl = \"http://es.example.com:9200\"\n// after\nurl = \"https://es.example.com:9200\"  # correct scheme/port verified with curl","handlingStrategy":"validation","validationCode":"import socket\nurl_host, url_port = \"es.example.com\", 9200\ns = socket.socket()\ns.settimeout(3)\ntry:\n    s.connect((url_host, url_port))\n    reachable = True\nexcept OSError:\n    reachable = False\nfinally:\n    s.close()","typeGuard":null,"tryCatchPattern":"try:\n    runner.test_connection()\nexcept Exception as e:\n    if str(e) == \"Connection refused\":\n        # transport-level failure: check URL/port/TLS, not the query\n        log_and_alert_network_issue(datasource_url)\n    else:\n        raise","preventionTips":["Verify host/port with curl or telnet before saving the data source","Prefer the elasticsearch2 runner for clearer error messages","Monitor Elasticsearch availability from the Redash host"],"tags":["network","elasticsearch","connection","configuration"],"backgroundTag":"connection-refused","analyzedSha":"ca79fe988d81cdac9675b412f3dfcab107bc1fbc","analyzedAt":"2026-08-28T18:32:34.637Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}