- Newest
- Most votes
- Most comments
The issue you're experiencing with your CloudWatch OpenSearch SQL query visualization is likely due to how OpenSearch SQL handles aliases in certain complex queries, especially those involving window functions.
When using window functions or other complex operations in OpenSearch SQL, the query engine sometimes retains both the original expression and the alias in the result set. This can lead to the situation you're seeing, where both the full expression and the alias appear in the visualization legend.
To address this, you could try a few approaches:
-
Simplify the query if possible, breaking it down into simpler parts or using a subquery.
-
Use a more descriptive alias that clearly represents what the calculation is doing. This way, even if both the expression and alias appear, the alias will be more meaningful.
-
If the visualization tool allows, you might be able to manually edit the legend labels after the query runs.
-
Consider using the Piped Processing Language (PPL) instead of SQL for this type of query, as it might handle the aliasing more cleanly in some cases.
As for the blank second column, this could be because the lag function is not finding a previous value for the first row, resulting in a null value. You might want to use a COALESCE function or similar to handle this case.
Regarding your attempt to use a subquery, it's worth noting that OpenSearch SQL has some limitations with nested queries and complex operations. Only one level of nested subqueries is supported, which might explain why you had difficulty getting it to work.
If you continue to face issues, you might want to consider breaking down the query into simpler parts or using materialized views if available in your setup to precompute some of the complex calculations.
Sources
OpenSearch SQL language - Amazon CloudWatch Logs
Amazon CloudWatch and Amazon OpenSearch Service launch an integrated analytics experience - AWS

Thanks for your help. This seems like a bug. Can I submit it as a bug somewere?