getredash/redash · error · Exception
Redash failed to parse the results it got from Elasticsearch
Error message
Redash failed to parse the results it got from Elasticsearch.
What it means
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.
Source
Thrown at redash/query_runner/elasticsearch2.py:236
elif "hits" in raw_result and "hits" in raw_result["hits"]:
for h in raw_result["hits"]["hits"]:
row = {}
fields_parameter_name = "_source" if "_source" in h else "fields"
for column in h[fields_parameter_name]:
if result_fields and column not in result_fields_index:
continue
unested_results = get_flatten_results({column: h[fields_parameter_name][column]})
for column_name, value in unested_results.items():
add_column_if_needed(column_name, value=value)
row[column_name] = value
result_rows.append(row)
else:
raise Exception("Redash failed to parse the results it got from Elasticsearch.")
return {"columns": result_columns, "rows": result_rows}
class OpenDistroSQLElasticSearch(ElasticSearch2):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.syntax = "sql"
def _build_query(self, query: str) -> Tuple[dict, str, Optional[list]]:
sql_query = {"query": query}
sql_query_url = "/_opendistro/_sql"
return sql_query, sql_query_url, None
@classmethod
def name(cls):
return "Open Distro SQL Elasticsearch"
View on GitHub (pinned to ca79fe988d)
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
Defensive patterns
Strategy: fallback
Try / catch
try:
data, error = es2.run_query(q, user)
except Exception as e:
if "failed to parse" in str(e):
# re-run via a raw-JSON runner for inspection
data, error = json_ds_runner.run_query(json.dumps({"url": es_url, "path": "aggregations"}), user) Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Redash failed to parse the results it got from Elasticsearch
- Failed to execute query. Return Code: {0} Reason: {1}
- Connection refused
- Advanced queries are not supported
- Results format not supported
AI-assisted analysis of getredash/redash@ca79fe988d (2026-08-28).
Data as JSON: /api/errors/3af2ae1d2c2f1f4a.
Report an issue: GitHub.