{"record":{"id":"38ae8a73deb53b94","repo":"getredash/redash","slug":"failed-to-execute-query-return-code-0-reason","errorCode":null,"errorMessage":"Failed to execute query. Return Code: {0}   Reason: {1}","messagePattern":"Failed to execute query\\. Return Code: (.+?)   Reason: (.+?)","errorType":"http","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"redash/query_runner/elasticsearch.py","lineNumber":330,"sourceCode":"                    if result_fields and column not in result_fields_index:\n                        continue\n\n                    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)","sourceCodeStart":312,"sourceCodeEnd":348,"githubUrl":"https://github.com/getredash/redash/blob/ca79fe988d81cdac9675b412f3dfcab107bc1fbc/redash/query_runner/elasticsearch.py#L312-L348","documentation":"Elasticsearch runner's test_connection GETs /_cluster/health and on requests.HTTPError (a 4xx/5xx was returned) re-raises with the status code and body text. Transport succeeded but the server rejected the request.","triggerScenarios":"Clicking Test Connection when /_cluster/health returns 401 (bad basic-auth), 403 (security restrictions), 404 (wrong URL/base path), or 503 (ES still starting).","commonSituations":"Wrong X-Pack credentials, URL with a missing or wrong path prefix, a gateway blocking the health endpoint, or the cluster still booting.","solutions":["curl -u user:pass https://host/_cluster/health and match the status: 401 → fix credentials, 403 → security role, 404 → fix URL/base path","Correct the server URL including any path prefix","Wait for ES to come up (503) and retest","Grant the user the cluster monitor privilege for the health endpoint"],"exampleFix":"# before\n{\"server\": \"https://es.example.com/old-prefix\", \"basic_auth_user\": \"u\", \"basic_auth_password\": \"wrong\"}\n\n# after\n{\"server\": \"https://es.example.com:9200\", \"basic_auth_user\": \"u\", \"basic_auth_password\": \"correct\"}","handlingStrategy":"validation","validationCode":"import requests\nr = requests.get(f'{server}/_cluster/health', auth=auth, timeout=5)\nassert r.status_code == 200, f'{r.status_code}: {r.text[:200]}'","typeGuard":null,"tryCatchPattern":"try:\n    runner.test_connection()\nexcept Exception as e:\n    if 'Return Code:' in str(e):\n        code, _, reason = str(e).partition('Return Code:')[2].partition('Reason:')\n        route(code.strip())  # 401 creds, 403 security, 404 URL, 503 wait","preventionTips":["curl /_cluster/health before saving or editing ES data sources","Keep the ES URL including path prefixes exact","Grant the monitoring user the cluster-monitor privilege"],"tags":["redash","elasticsearch","health-check","http-error"],"backgroundTag":"health-check-failed","analyzedSha":"ca79fe988d81cdac9675b412f3dfcab107bc1fbc","analyzedAt":"2026-08-28T18:32:34.637Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}