From 89d24c942aec239b7dbee7c4298445862a108d45 Mon Sep 17 00:00:00 2001 From: Raphael Gaschignard Date: Mon, 24 Aug 2026 11:02:19 +1000 Subject: [PATCH] fix: fix group by terms The plugin would allow for p95 metrics, but then, when referencing them, would look up by "p95.0"s. This seems to be an elastic search oddity that Quickwit doesn't do --- .../TermsSettingsEditor.test.tsx | 18 ++++++++++++++++-- .../SettingsEditor/TermsSettingsEditor.tsx | 8 ++++---- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/components/QueryEditor/BucketAggregationsEditor/SettingsEditor/TermsSettingsEditor.test.tsx b/src/components/QueryEditor/BucketAggregationsEditor/SettingsEditor/TermsSettingsEditor.test.tsx index f8be73f..fa40757 100644 --- a/src/components/QueryEditor/BucketAggregationsEditor/SettingsEditor/TermsSettingsEditor.test.tsx +++ b/src/components/QueryEditor/BucketAggregationsEditor/SettingsEditor/TermsSettingsEditor.test.tsx @@ -2,9 +2,9 @@ import { screen } from '@testing-library/react'; import React from 'react'; import selectEvent from 'react-select-event'; -import { ElasticsearchQuery, Terms, Average, Derivative, TopMetrics } from '@/types'; +import { ElasticsearchQuery, Terms, Average, Derivative, TopMetrics, Percentiles } from '@/types'; -import { TermsSettingsEditor } from './TermsSettingsEditor'; +import { TermsSettingsEditor, createOrderByOptions } from './TermsSettingsEditor'; import { describeMetric } from 'utils'; import { renderWithESProvider } from 'test-helpers/render'; @@ -39,4 +39,18 @@ describe('Terms Settings Editor', () => { // All other metric aggregations can be used in order by expect(await screen.findByText(describeMetric(avg))).toBeInTheDocument(); }); + + it('Order by option value for a whole-number percentile should not append ".0"', () => { + // Quickwit's aggregation engine names the percentile sub-aggregation after the + // percent value exactly as sent in the request (e.g. "95"), unlike Elasticsearch + // which requires a ".0" suffix for whole-number bucket paths (e.g. "95.0"). + // Sending an orderBy of "1[95.0]" makes Quickwit fail with + // "could not find aggregation with name 1[95] in metric sub_aggregations". + const percentiles: Percentiles = { id: '1', type: 'percentiles', field: '@value', settings: { percents: ['95'] } }; + + const options = createOrderByOptions([percentiles]); + + expect(options.some((option) => option.value === '1[95]')).toBe(true); + expect(options.some((option) => option.value === '1[95.0]')).toBe(false); + }); }); diff --git a/src/components/QueryEditor/BucketAggregationsEditor/SettingsEditor/TermsSettingsEditor.tsx b/src/components/QueryEditor/BucketAggregationsEditor/SettingsEditor/TermsSettingsEditor.tsx index 9fcb0a2..d52e226 100644 --- a/src/components/QueryEditor/BucketAggregationsEditor/SettingsEditor/TermsSettingsEditor.tsx +++ b/src/components/QueryEditor/BucketAggregationsEditor/SettingsEditor/TermsSettingsEditor.tsx @@ -123,10 +123,10 @@ function createOrderByOptionsForPercentiles(metric: Percentiles): Array { - // The bucket path for percentile numbers is appended with a `.0` if the number is whole - // otherwise you have to use the actual value. - const percentString = /^\d+\.\d+/.test(`${percent}`) ? percent : `${percent}.0`; - return { label: `${describeMetric(metric)} (${percent})`, value: `${metric.id}[${percentString}]` }; + // Unlike Elasticsearch, Quickwit's aggregation engine names the percentile + // sub-aggregation after the percent value exactly as sent in the request + // (e.g. "95"), without appending `.0` for whole numbers. + return { label: `${describeMetric(metric)} (${percent})`, value: `${metric.id}[${percent}]` }; }); }