{"record":{"id":"d1f91a385cf9a6fd","repo":"getredash/redash","slug":"redash-failed-to-parse-the-results-it-got-from-ela","errorCode":null,"errorMessage":"Redash failed to parse the results it got from Elasticsearch.","messagePattern":"Redash failed to parse the results it got from Elasticsearch\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"redash/query_runner/elasticsearch.py","lineNumber":322,"sourceCode":"                for field in result_fields:\n                    add_column_if_needed(mappings, field, field, result_columns, result_columns_index)\n\n            for h in raw_result[\"hits\"][\"hits\"]:\n                row = {}\n\n                column_name = \"_source\" if \"_source\" in h else \"fields\"\n                for column in h[column_name]:\n                    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","sourceCodeStart":304,"sourceCodeEnd":340,"githubUrl":"https://github.com/getredash/redash/blob/ca79fe988d81cdac9675b412f3dfcab107bc1fbc/redash/query_runner/elasticsearch.py#L304-L340","documentation":"Elasticsearch runner's _parse_results raises this when the response matches neither the aggregation branch nor the hits branch it can tabulate — Redash received a response but its columns/rows extraction found nothing parseable (the else of the dispatch).","triggerScenarios":"Querying Elasticsearch in simple-query mode where the response contains neither aggregations nor standard hits/_source/fields — e.g. unexpected top-level keys or a field layout the runner doesn't recognize.","commonSituations":"Elasticsearch 7→8 response-format differences, unmapped fields, or query DSL producing an unanticipated structure.","solutions":["Switch the query to explicit JSON/DSL mode with an _source field list","Test the same query with curl against _search and inspect the response structure","Upgrade Redash to a runner version supporting your Elasticsearch major version","Restrict the query to fields that exist per the index mapping"],"exampleFix":"# before\n{\"query\": {\"match_all\": {}}}\n\n# after\n{\"query\": {\"match_all\": {}}, \"_source\": [\"field1\", \"field2\"]}","handlingStrategy":"fallback","validationCode":"import requests\nr = requests.post(f'{server}/{index}/_search', auth=auth, json={'query': {'match_all': {}}, 'size': 1})\nbody = r.json()\nassert 'hits' in body or 'aggregations' in body, f'unparseable shape: {list(body)}'","typeGuard":"def has_parseable_es_shape(body: dict) -> bool:\n    return isinstance(body, dict) and ('aggregations' in body or 'hits' in body)","tryCatchPattern":"try:\n    data, err = es_runner.run_query(q, u)\nexcept Exception as e:\n    if 'failed to parse the results' in str(e):\n        data, err = es_runner.run_query(to_dsl_query_with_source(q), u)  # fallback to explicit DSL","preventionTips":["Prefer explicit query DSL with _source field lists","Test queries with curl against the target ES major version","Upgrade Redash alongside Elasticsearch upgrades"],"tags":["redash","elasticsearch","response-parsing"],"backgroundTag":"unexpected-api-response","analyzedSha":"ca79fe988d81cdac9675b412f3dfcab107bc1fbc","analyzedAt":"2026-08-28T18:32:34.637Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}