{"record":{"id":"3af2ae1d2c2f1f4a","repo":"getredash/redash","slug":"redash-failed-to-parse-the-results-it-got-from-ela-3af2ae","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/elasticsearch2.py","lineNumber":236,"sourceCode":"\n        elif \"hits\" in raw_result and \"hits\" in raw_result[\"hits\"]:\n            for h in raw_result[\"hits\"][\"hits\"]:\n                row = {}\n\n                fields_parameter_name = \"_source\" if \"_source\" in h else \"fields\"\n                for column in h[fields_parameter_name]:\n                    if result_fields and column not in result_fields_index:\n                        continue\n\n                    unested_results = get_flatten_results({column: h[fields_parameter_name][column]})\n\n                    for column_name, value in unested_results.items():\n                        add_column_if_needed(column_name, value=value)\n                        row[column_name] = value\n\n                result_rows.append(row)\n        else:\n            raise Exception(\"Redash failed to parse the results it got from Elasticsearch.\")\n\n        return {\"columns\": result_columns, \"rows\": result_rows}\n\n\nclass OpenDistroSQLElasticSearch(ElasticSearch2):\n    def __init__(self, *args, **kwargs):\n        super().__init__(*args, **kwargs)\n        self.syntax = \"sql\"\n\n    def _build_query(self, query: str) -> Tuple[dict, str, Optional[list]]:\n        sql_query = {\"query\": query}\n        sql_query_url = \"/_opendistro/_sql\"\n        return sql_query, sql_query_url, None\n\n    @classmethod\n    def name(cls):\n        return \"Open Distro SQL Elasticsearch\"\n","sourceCodeStart":218,"sourceCodeEnd":254,"githubUrl":"https://github.com/getredash/redash/blob/ca79fe988d81cdac9675b412f3dfcab107bc1fbc/redash/query_runner/elasticsearch2.py#L218-L254","documentation":"ElasticSearch2's _parse_results inspects the aggregations/hits shape returned by Elasticsearch; when the response matches none of the handled layouts (aggregations with buckets, nested aggs, plain hits), it raises 'Redash failed to parse the results'. It signals an unrecognized response structure rather than a bad query.","triggerScenarios":"Running an Elasticsearch query whose response uses aggregation types or result shapes the parser does not handle — e.g. certain composite/nested aggregations,管道 aggs, or responses with no 'aggregations' and no 'hits.hits' key. Also when the request returned an error payload that was not surfaced as HTTPError.","commonSituations":"Querying newer Elasticsearch versions whose response layout differs, using rare aggregation types (percentiles as single-value, nested date_histogram), or hitting an error JSON with status 200.","solutions":["Simplify the query: use standard terms/date_histogram buckets and check it in Kibana/curl first","Inspect the raw response with curl to identify the aggregation shape and restructure it (flatten nested aggs)","Upgrade Redash — the elasticsearch2 parser has been extended over versions to cover more agg types","As a workaround, use a scripted/HTTP query runner (json_ds or Python) that returns raw JSON"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    data, error = es2.run_query(q, user)\nexcept Exception as e:\n    if \"failed to parse\" in str(e):\n        # re-run via a raw-JSON runner for inspection\n        data, error = json_ds_runner.run_query(json.dumps({\"url\": es_url, \"path\": \"aggregations\"}), user)","preventionTips":["Test aggregation queries in Kibana/curl first to know the response shape","Prefer common aggregation types (terms, date_histogram)","Keep Redash updated for new aggregation parsers"],"tags":["elasticsearch","parsing","aggregations"],"backgroundTag":"response-parse-failure","analyzedSha":"ca79fe988d81cdac9675b412f3dfcab107bc1fbc","analyzedAt":"2026-08-28T18:32:34.637Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}