[Metrics][Discover] Fix fields dropdown by casting dimension fields to string#242432
Conversation
src/platform/plugins/shared/metrics_experience/server/routes/dimensions/get_dimensions.ts
Show resolved
Hide resolved
| const source = fromCommand(indices); | ||
| const query = source | ||
| .pipe( | ||
| evaluate('??dim = ??dim::string', { dim: dimensions[0] }), |
There was a problem hiding this comment.
For now, it's ok, but in the future, we might support multi-dimensions, and we'll have to rethink this query.
| dim: dimensions[0], | ||
| }), | ||
| sort('??dim', { dim: dimensions[0] }), | ||
| limit(1000) |
There was a problem hiding this comment.
Should we increase the number of items returned?
There was a problem hiding this comment.
I don't know, it's what I saw on your POC, should I keep it to 20 then?
...platform/packages/shared/kbn-unified-metrics-grid/src/common/utils/esql/create_esql_query.ts
Show resolved
Hide resolved
|
@jennypavlova I couldn't reproduce the error, but I will check as @crespocarlos mention to add it also for the IN clause |
src/platform/plugins/shared/metrics_experience/server/routes/dimensions/get_dimensions.ts
Show resolved
Hide resolved
59559f9 to
f5071f6
Compare
101a7a6 to
751603a
Compare
ed9f7b2 to
b69c0e9
Compare
| @@ -0,0 +1,307 @@ | |||
| /* | |||
There was a problem hiding this comment.
We already have a functional test covering this, btw.
There was a problem hiding this comment.
yes, the one failing 😅
I can remove delete this unit test then
| const response = await esClient.esql( | ||
| 'get_dimensions', | ||
| { | ||
| query: query.toString(), |
There was a problem hiding this comment.
we already call toString() on line 47. Do we need this one too?
|
Thanks @crespocarlos for the fix, I tested it and run the api test and works as expected |
💛 Build succeeded, but was flaky
Failed CI StepsTest Failures
Metrics [docs]Async chunks
History
|
|
Starting backport for target branches: 9.2 https://github.com/elastic/kibana/actions/runs/19327018702 |
💔 All backports failed
Manual backportTo create the backport manually run: Questions ?Please refer to the Backport tool documentation |
💚 All backports created successfully
Note: Successful backport PRs will be merged automatically after passing CI. Questions ?Please refer to the Backport tool documentation |
…o string (elastic#242432) Closes elastic#239952 ### Summary This PR resolves the data inconsistency between metric charts and the "Filter by value" dropdown, where values visible in charts were missing from the filter list. #### Problem The root cause was that the same dimension field (e.g., `attributes.cpu`) could have different data types across different indices: - `long` in one index - `keyword` in another index Elasticsearch aggregations and ES|QL queries fail when trying to process fields with inconsistent types, resulting in incomplete dimension values in the dropdown. #### Solution **1. Updated `get_dimentions.ts`:** - Migrated from Elasticsearch `_search` API with `terms` aggregations to ES|QL - Added explicit type casting to string using `::STRING` syntax - Increased dimension value limit from 20 to 1000 - Simplified response mapping logic **2. Updated `create_esql_query.ts`:** - Added type casting logic for dimensions in `WHERE` clauses - Applied the same `needsStringCasting()` check used in `CONCAT` operations - Ensures consistent string type handling for null checks BEFORE <img width="2304" height="560" alt="image" src="https://github.com/user-attachments/assets/e74c73af-838e-4282-b6f7-9778f03e562d" /> AFTER <img width="1043" height="292" alt="Screenshot 2025-11-10 at 14 37 35" src="https://github.com/user-attachments/assets/ade48ce5-1290-4fc7-afb4-57adcf3ebaf3" /> --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Carlos Crespo <carloshenrique.leonelcrespo@elastic.co> (cherry picked from commit 08460f6) # Conflicts: # src/platform/packages/shared/kbn-traced-es-client/src/create_traced_es_client.ts # src/platform/plugins/shared/metrics_experience/tsconfig.json
…o string (elastic#242432) Closes elastic#239952 ### Summary This PR resolves the data inconsistency between metric charts and the "Filter by value" dropdown, where values visible in charts were missing from the filter list. #### Problem The root cause was that the same dimension field (e.g., `attributes.cpu`) could have different data types across different indices: - `long` in one index - `keyword` in another index Elasticsearch aggregations and ES|QL queries fail when trying to process fields with inconsistent types, resulting in incomplete dimension values in the dropdown. #### Solution **1. Updated `get_dimentions.ts`:** - Migrated from Elasticsearch `_search` API with `terms` aggregations to ES|QL - Added explicit type casting to string using `::STRING` syntax - Increased dimension value limit from 20 to 1000 - Simplified response mapping logic **2. Updated `create_esql_query.ts`:** - Added type casting logic for dimensions in `WHERE` clauses - Applied the same `needsStringCasting()` check used in `CONCAT` operations - Ensures consistent string type handling for null checks BEFORE <img width="2304" height="560" alt="image" src="https://github.com/user-attachments/assets/e74c73af-838e-4282-b6f7-9778f03e562d" /> AFTER <img width="1043" height="292" alt="Screenshot 2025-11-10 at 14 37 35" src="https://github.com/user-attachments/assets/ade48ce5-1290-4fc7-afb4-57adcf3ebaf3" /> --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Carlos Crespo <carloshenrique.leonelcrespo@elastic.co>




Closes #239952
Summary
This PR resolves the data inconsistency between metric charts and the "Filter by value" dropdown, where values visible in charts were missing from the filter list.
Problem
The root cause was that the same dimension field (e.g.,
attributes.cpu) could have different data types across different indices:longin one indexkeywordin another indexElasticsearch aggregations and ES|QL queries fail when trying to process fields with inconsistent types, resulting in incomplete dimension values in the dropdown.
Solution
1. Updated
get_dimentions.ts:_searchAPI withtermsaggregations to ES|QL::STRINGsyntax2. Updated
create_esql_query.ts:WHEREclausesneedsStringCasting()check used inCONCAToperationsBEFORE

AFTER
