#159358·elasticsearch

ES|QL|DS: CHANGE_POINT + STATS + INLINE STATS causes HTTP 500 when FROM mixes external and ES sources

Author: luigidellaquilaCreated Sep 15, 2026Updated Sep 17, 2026
Labels>bugTeam:Analytics:Analytics/ES|QLES|QL|DS

Problem

Combining CHANGE_POINT, STATS ... BY <field>, and INLINE STATS COUNT(TO_STRING(<field>)) in a query that mixes an external dataset (e.g. parquet) with a plain ES index causes HTTP 500. The optimizer loses the intermediate type-converted reference ($$<field>$converted_to$<type>) that ExternalSourceResolver introduces during schema merging.

The same pipeline against a single source — parquet only, or ES only — succeeds.

Minimal reproducer

FROM parquet_employees, employees
| CHANGE_POINT emp_no ON birth_date AS cp_low, cp_high
| STATS max_salary = MAX(salary) BY gender
| INLINE STATS cp_count = COUNT(TO_STRING(gender))

Response (HTTP 500):

{
  "error": {
    "type": "illegal_state_exception",
    "reason": "Plan [...] optimized incorrectly due to missing references [$$gender$converted_to$keyword{r$}#...]"
  },
  "status": 500
}

Same pipeline with ES-only source returns results with no error:

FROM employees | CHANGE_POINT emp_no ON birth_date AS cp_low, cp_high | STATS max_salary = MAX(salary) BY gender | INLINE STATS cp_count = COUNT(TO_STRING(gender))

Root cause (initial analysis)

ExternalSourceResolver rewrites the plan when merging schemas across heterogeneous sources (external + ES). During this rewrite it inserts type-converted references such as $$gender$converted_to$keyword. A subsequent physical optimizer rule drops these references before INLINE STATS can consume them, causing PostOptimizationPhasePlanVerifier to report a missing reference.