Skip to content

ES|QL INLINESTATS after STATS optimized incorrectly #124654

@jan-elastic

Description

@jan-elastic

Elasticsearch Version

main

Installed Plugins

No response

Java Version

n/a

OS Version

n/a

Problem Description

FROM kibana_sample_data_ecommerce 
  | STATS price = SUM(taxful_total_price) BY day = BUCKET(order_date,1 DAY)
  | INLINESTATS days = TOP(day, 10, "ASC")

results in

[esql] > Unexpected error from Elasticsearch: illegal_state_exception - Found 1 problem
line 3:5: Plan [ProjectExec[[price{r}#1229, day{r}#1226, days{r}#1233]]] optimized incorrectly due to missing references [price{r}#1229]

I expected output like

 day  | price  | days
------+--------+-------------------
 day1 | price1 | [day1, day2, ...]
 day2 | price2 | [day1, day2, ...]
 ...  | ...    | ...

Steps to Reproduce

see above

Logs (if relevant)

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions