Skip to content

[ES|QL] Use correct timeFieldName for time brush filter #221322

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
May 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,28 @@ import { Filter, isRangeFilter, RangeFilter } from '../build_filters';
import { TimeRange } from './types';
import { convertRangeFilterToTimeRangeString } from './convert_range_filter';

export function extractTimeFilter(timeFieldName: string, filters: Filter[]) {
const [timeRangeFilter, restOfFilters] = partition(filters, (obj: Filter) => {
let key;

if (isRangeFilter(obj)) {
key = keys(obj.query.range)[0];
}

return Boolean(key && key === timeFieldName);
});
export function extractTimeFilter(
timeFieldName: string,
filters: Filter[]
): { restOfFilters: Filter[]; timeRangeFilter?: RangeFilter } {
const [timeRangeFilter, restOfFilters] = partition<Filter, RangeFilter>(
filters,
(f: Filter): f is RangeFilter => isRangeFilter(f) && timeFieldName === keys(f.query.range)[0]
);

return {
restOfFilters,
timeRangeFilter: timeRangeFilter[0] as RangeFilter | undefined,
timeRangeFilter: timeRangeFilter[0],
};
}

export function extractTimeRange(
filters: Filter[],
timeFieldName?: string
): { restOfFilters: Filter[]; timeRange?: TimeRange } {
if (!timeFieldName) return { restOfFilters: filters, timeRange: undefined };
if (!timeFieldName) {
return { restOfFilters: filters };
}
const { timeRangeFilter, restOfFilters } = extractTimeFilter(timeFieldName, filters);
return {
restOfFilters,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -661,12 +661,16 @@ export function XYChart({
? getAccessorByDimension(dataLayers[0].xAccessor, table.columns)
: undefined;
const xAxisColumnIndex = table.columns.findIndex((el) => el.id === xAccessor);

const context: BrushEvent['data'] = {
range: [min, max],
table,
column: xAxisColumnIndex,
...(isEsqlMode ? { timeFieldName: table.columns[xAxisColumnIndex].name } : {}),
...(isEsqlMode
? {
timeFieldName:
table.columns[xAxisColumnIndex].meta.sourceParams?.sourceField?.toString(),
}
: {}),
};
onSelectRange(context);
};
Expand Down
33 changes: 33 additions & 0 deletions src/platform/test/functional/apps/discover/esql/_esql_view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
const esql = getService('esql');
const dashboardAddPanel = getService('dashboardAddPanel');
const dataViews = getService('dataViews');
const elasticChart = getService('elasticChart');
const filterBar = getService('filterBar');

const { common, discover, dashboard, header, timePicker, unifiedFieldList, unifiedSearch } =
getPageObjects([
'common',
Expand Down Expand Up @@ -236,6 +239,36 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
const cell = await dataGrid.getCellElementExcludingControlColumns(0, 0);
expect(await cell.getVisibleText()).to.be('1');
});

it('should allow brushing time series', async () => {
await timePicker.setDefaultAbsoluteRange();
await discover.selectTextBaseLang();
await header.waitUntilLoadingHasFinished();
await discover.waitUntilSearchingHasFinished();
await unifiedFieldList.waitUntilSidebarHasLoaded();

const testQuery = `from logstash-* | limit 100`;

await monacoEditor.setCodeEditorValue(testQuery);
await testSubjects.click('querySubmitButton');
await header.waitUntilLoadingHasFinished();
await discover.waitUntilSearchingHasFinished();

const initialTimeConfig = await timePicker.getTimeConfigAsAbsoluteTimes();
expect(initialTimeConfig.start).to.equal(timePicker.defaultStartTime);
expect(initialTimeConfig.end).to.equal(timePicker.defaultEndTime);

const renderingCount = await elasticChart.getVisualizationRenderingCount();
await discover.brushHistogram();
await discover.waitUntilSearchingHasFinished();
// no filter pill created for time brush
expect(await filterBar.getFilterCount()).to.be(0);
// chart and time picker updated
await elasticChart.waitForRenderingCount(renderingCount + 1);
const updatedTimeConfig = await timePicker.getTimeConfigAsAbsoluteTimes();
expect(updatedTimeConfig.start).to.be('Sep 20, 2015 @ 08:41:22.854');
expect(updatedTimeConfig.end).to.be('Sep 21, 2015 @ 04:14:56.951');
});
});

describe('errors', () => {
Expand Down