Skip to content

Commit 921cc63

Browse files
committed
Merge branch 'discover/enable-fields-api-712' into backport/7.12/pr-91815
2 parents d33b58e + b95fd78 commit 921cc63

20 files changed

Lines changed: 407 additions & 46 deletions

File tree

docs/development/plugins/data/public/kibana-plugin-plugins-data-public.search.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ search: {
4646
boundLabel: string;
4747
intervalLabel: string;
4848
})[];
49+
getNumberHistogramIntervalByDatatableColumn: (column: import("../../expressions").DatatableColumn) => number | undefined;
4950
};
5051
getRequestInspectorStats: typeof getRequestInspectorStats;
5152
getResponseInspectorStats: typeof getResponseInspectorStats;

src/plugins/data/common/search/aggs/buckets/histogram.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { AggTypesDependencies } from '../agg_types';
1212
import { BUCKET_TYPES } from './bucket_agg_types';
1313
import { IBucketHistogramAggConfig, getHistogramBucketAgg, AutoBounds } from './histogram';
1414
import { BucketAggType } from './bucket_agg_type';
15+
import { SerializableState } from 'src/plugins/expressions/common';
1516

1617
describe('Histogram Agg', () => {
1718
let aggTypesDependencies: AggTypesDependencies;
@@ -230,6 +231,27 @@ describe('Histogram Agg', () => {
230231
expect(params.interval).toBeNaN();
231232
});
232233

234+
test('will serialize the auto interval along with the actually chosen interval and deserialize correctly', () => {
235+
const aggConfigs = getAggConfigs({
236+
interval: 'auto',
237+
field: {
238+
name: 'field',
239+
},
240+
});
241+
(aggConfigs.aggs[0] as IBucketHistogramAggConfig).setAutoBounds({ min: 0, max: 1000 });
242+
const serializedAgg = aggConfigs.aggs[0].serialize();
243+
const serializedIntervalParam = (serializedAgg.params as SerializableState).used_interval;
244+
expect(serializedIntervalParam).toBe(500);
245+
const freshHistogramAggConfig = getAggConfigs({
246+
interval: 100,
247+
field: {
248+
name: 'field',
249+
},
250+
}).aggs[0];
251+
freshHistogramAggConfig.setParams(serializedAgg.params);
252+
expect(freshHistogramAggConfig.getParam('interval')).toEqual('auto');
253+
});
254+
233255
describe('interval scaling', () => {
234256
const getInterval = (
235257
maxBars: number,

src/plugins/data/common/search/aggs/buckets/histogram.ts

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import { get } from 'lodash';
1010
import { i18n } from '@kbn/i18n';
11+
import { IUiSettingsClient } from 'kibana/public';
1112

1213
import { KBN_FIELD_TYPES, UI_SETTINGS } from '../../../../common';
1314
import { AggTypesDependencies } from '../agg_types';
@@ -39,6 +40,7 @@ export interface IBucketHistogramAggConfig extends IBucketAggConfig {
3940
export interface AggParamsHistogram extends BaseAggParams {
4041
field: string;
4142
interval: number | string;
43+
used_interval?: number | string;
4244
maxBars?: number;
4345
intervalBase?: number;
4446
min_doc_count?: boolean;
@@ -141,17 +143,22 @@ export const getHistogramBucketAgg = ({
141143
});
142144
},
143145
write(aggConfig, output) {
144-
const values = aggConfig.getAutoBounds();
145-
146-
output.params.interval = calculateHistogramInterval({
147-
values,
148-
interval: aggConfig.params.interval,
149-
maxBucketsUiSettings: getConfig(UI_SETTINGS.HISTOGRAM_MAX_BARS),
150-
maxBucketsUserInput: aggConfig.params.maxBars,
151-
intervalBase: aggConfig.params.intervalBase,
152-
esTypes: aggConfig.params.field?.spec?.esTypes || [],
153-
});
146+
output.params.interval = calculateInterval(aggConfig, getConfig);
147+
},
148+
},
149+
{
150+
name: 'used_interval',
151+
default: autoInterval,
152+
shouldShow() {
153+
return false;
154154
},
155+
write: () => {},
156+
serialize(val, aggConfig) {
157+
if (!aggConfig) return undefined;
158+
// store actually used auto interval in serialized agg config to be able to read it from the result data table meta information
159+
return calculateInterval(aggConfig, getConfig);
160+
},
161+
toExpressionAst: () => undefined,
155162
},
156163
{
157164
name: 'maxBars',
@@ -193,3 +200,18 @@ export const getHistogramBucketAgg = ({
193200
},
194201
],
195202
});
203+
204+
function calculateInterval(
205+
aggConfig: IBucketHistogramAggConfig,
206+
getConfig: IUiSettingsClient['get']
207+
): any {
208+
const values = aggConfig.getAutoBounds();
209+
return calculateHistogramInterval({
210+
values,
211+
interval: aggConfig.params.interval,
212+
maxBucketsUiSettings: getConfig(UI_SETTINGS.HISTOGRAM_MAX_BARS),
213+
maxBucketsUserInput: aggConfig.params.maxBars,
214+
intervalBase: aggConfig.params.intervalBase,
215+
esTypes: aggConfig.params.field?.spec?.esTypes || [],
216+
});
217+
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
5+
* in compliance with, at your election, the Elastic License 2.0 or the Server
6+
* Side Public License, v 1.
7+
*/
8+
9+
import { getNumberHistogramIntervalByDatatableColumn } from '.';
10+
import { BUCKET_TYPES } from '../buckets';
11+
12+
describe('getNumberHistogramIntervalByDatatableColumn', () => {
13+
it('returns nothing on column from other data source', () => {
14+
expect(
15+
getNumberHistogramIntervalByDatatableColumn({
16+
id: 'test',
17+
name: 'test',
18+
meta: {
19+
type: 'date',
20+
source: 'essql',
21+
},
22+
})
23+
).toEqual(undefined);
24+
});
25+
26+
it('returns nothing on non histogram column', () => {
27+
expect(
28+
getNumberHistogramIntervalByDatatableColumn({
29+
id: 'test',
30+
name: 'test',
31+
meta: {
32+
type: 'date',
33+
source: 'esaggs',
34+
sourceParams: {
35+
type: BUCKET_TYPES.TERMS,
36+
},
37+
},
38+
})
39+
).toEqual(undefined);
40+
});
41+
42+
it('returns interval on resolved auto interval', () => {
43+
expect(
44+
getNumberHistogramIntervalByDatatableColumn({
45+
id: 'test',
46+
name: 'test',
47+
meta: {
48+
type: 'date',
49+
source: 'esaggs',
50+
sourceParams: {
51+
type: BUCKET_TYPES.HISTOGRAM,
52+
params: {
53+
interval: 'auto',
54+
used_interval: 20,
55+
},
56+
},
57+
},
58+
})
59+
).toEqual(20);
60+
});
61+
62+
it('returns interval on fixed interval', () => {
63+
expect(
64+
getNumberHistogramIntervalByDatatableColumn({
65+
id: 'test',
66+
name: 'test',
67+
meta: {
68+
type: 'date',
69+
source: 'esaggs',
70+
sourceParams: {
71+
type: BUCKET_TYPES.HISTOGRAM,
72+
params: {
73+
interval: 7,
74+
used_interval: 7,
75+
},
76+
},
77+
},
78+
})
79+
).toEqual(7);
80+
});
81+
82+
it('returns undefined if information is not available', () => {
83+
expect(
84+
getNumberHistogramIntervalByDatatableColumn({
85+
id: 'test',
86+
name: 'test',
87+
meta: {
88+
type: 'date',
89+
source: 'esaggs',
90+
sourceParams: {
91+
type: BUCKET_TYPES.HISTOGRAM,
92+
params: {},
93+
},
94+
},
95+
})
96+
).toEqual(undefined);
97+
});
98+
});
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
5+
* in compliance with, at your election, the Elastic License 2.0 or the Server
6+
* Side Public License, v 1.
7+
*/
8+
9+
import { DatatableColumn } from 'src/plugins/expressions/common';
10+
import type { AggParamsHistogram } from '../buckets';
11+
import { BUCKET_TYPES } from '../buckets/bucket_agg_types';
12+
13+
/**
14+
* Helper function returning the used interval for data table column created by the histogramm agg type.
15+
* "auto" will get expanded to the actually used interval.
16+
* If the column is not a column created by a histogram aggregation of the esaggs data source,
17+
* this function will return undefined.
18+
*/
19+
export const getNumberHistogramIntervalByDatatableColumn = (column: DatatableColumn) => {
20+
if (column.meta.source !== 'esaggs') return;
21+
if (column.meta.sourceParams?.type !== BUCKET_TYPES.HISTOGRAM) return;
22+
const params = (column.meta.sourceParams.params as unknown) as AggParamsHistogram;
23+
24+
if (!params.used_interval || typeof params.used_interval === 'string') {
25+
return undefined;
26+
}
27+
return params.used_interval;
28+
};

src/plugins/data/common/search/aggs/utils/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88

99
export * from './calculate_auto_time_expression';
10+
export { getNumberHistogramIntervalByDatatableColumn } from './get_number_histogram_interval';
1011
export * from './date_interval_utils';
1112
export * from './get_format_with_aggs';
1213
export * from './ipv4_address';

src/plugins/data/public/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ import {
308308
parseInterval,
309309
toAbsoluteDates,
310310
boundsDescendingRaw,
311+
getNumberHistogramIntervalByDatatableColumn,
311312
// expressions utils
312313
getRequestInspectorStats,
313314
getResponseInspectorStats,
@@ -417,6 +418,7 @@ export const search = {
417418
termsAggFilter,
418419
toAbsoluteDates,
419420
boundsDescendingRaw,
421+
getNumberHistogramIntervalByDatatableColumn,
420422
},
421423
getRequestInspectorStats,
422424
getResponseInspectorStats,

src/plugins/data/public/public.api.md

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2243,6 +2243,7 @@ export const search: {
22432243
boundLabel: string;
22442244
intervalLabel: string;
22452245
})[];
2246+
getNumberHistogramIntervalByDatatableColumn: (column: import("../../expressions").DatatableColumn) => number | undefined;
22462247
};
22472248
getRequestInspectorStats: typeof getRequestInspectorStats;
22482249
getResponseInspectorStats: typeof getResponseInspectorStats;
@@ -2652,21 +2653,21 @@ export const UI_SETTINGS: {
26522653
// src/plugins/data/public/index.ts:234:27 - (ae-forgotten-export) The symbol "validateIndexPattern" needs to be exported by the entry point index.d.ts
26532654
// src/plugins/data/public/index.ts:234:27 - (ae-forgotten-export) The symbol "flattenHitWrapper" needs to be exported by the entry point index.d.ts
26542655
// src/plugins/data/public/index.ts:234:27 - (ae-forgotten-export) The symbol "formatHitProvider" needs to be exported by the entry point index.d.ts
2655-
// src/plugins/data/public/index.ts:398:20 - (ae-forgotten-export) The symbol "getRequestInspectorStats" needs to be exported by the entry point index.d.ts
2656-
// src/plugins/data/public/index.ts:398:20 - (ae-forgotten-export) The symbol "getResponseInspectorStats" needs to be exported by the entry point index.d.ts
2657-
// src/plugins/data/public/index.ts:398:20 - (ae-forgotten-export) The symbol "tabifyAggResponse" needs to be exported by the entry point index.d.ts
2658-
// src/plugins/data/public/index.ts:398:20 - (ae-forgotten-export) The symbol "tabifyGetColumns" needs to be exported by the entry point index.d.ts
2659-
// src/plugins/data/public/index.ts:400:1 - (ae-forgotten-export) The symbol "CidrMask" needs to be exported by the entry point index.d.ts
2660-
// src/plugins/data/public/index.ts:401:1 - (ae-forgotten-export) The symbol "dateHistogramInterval" needs to be exported by the entry point index.d.ts
2661-
// src/plugins/data/public/index.ts:410:1 - (ae-forgotten-export) The symbol "InvalidEsCalendarIntervalError" needs to be exported by the entry point index.d.ts
2662-
// src/plugins/data/public/index.ts:411:1 - (ae-forgotten-export) The symbol "InvalidEsIntervalFormatError" needs to be exported by the entry point index.d.ts
2663-
// src/plugins/data/public/index.ts:412:1 - (ae-forgotten-export) The symbol "Ipv4Address" needs to be exported by the entry point index.d.ts
2664-
// src/plugins/data/public/index.ts:413:1 - (ae-forgotten-export) The symbol "isDateHistogramBucketAggConfig" needs to be exported by the entry point index.d.ts
2665-
// src/plugins/data/public/index.ts:417:1 - (ae-forgotten-export) The symbol "isValidEsInterval" needs to be exported by the entry point index.d.ts
2666-
// src/plugins/data/public/index.ts:418:1 - (ae-forgotten-export) The symbol "isValidInterval" needs to be exported by the entry point index.d.ts
2667-
// src/plugins/data/public/index.ts:421:1 - (ae-forgotten-export) The symbol "parseInterval" needs to be exported by the entry point index.d.ts
2668-
// src/plugins/data/public/index.ts:422:1 - (ae-forgotten-export) The symbol "propFilter" needs to be exported by the entry point index.d.ts
2669-
// src/plugins/data/public/index.ts:425:1 - (ae-forgotten-export) The symbol "toAbsoluteDates" needs to be exported by the entry point index.d.ts
2656+
// src/plugins/data/public/index.ts:399:20 - (ae-forgotten-export) The symbol "getRequestInspectorStats" needs to be exported by the entry point index.d.ts
2657+
// src/plugins/data/public/index.ts:399:20 - (ae-forgotten-export) The symbol "getResponseInspectorStats" needs to be exported by the entry point index.d.ts
2658+
// src/plugins/data/public/index.ts:399:20 - (ae-forgotten-export) The symbol "tabifyAggResponse" needs to be exported by the entry point index.d.ts
2659+
// src/plugins/data/public/index.ts:399:20 - (ae-forgotten-export) The symbol "tabifyGetColumns" needs to be exported by the entry point index.d.ts
2660+
// src/plugins/data/public/index.ts:401:1 - (ae-forgotten-export) The symbol "CidrMask" needs to be exported by the entry point index.d.ts
2661+
// src/plugins/data/public/index.ts:402:1 - (ae-forgotten-export) The symbol "dateHistogramInterval" needs to be exported by the entry point index.d.ts
2662+
// src/plugins/data/public/index.ts:411:1 - (ae-forgotten-export) The symbol "InvalidEsCalendarIntervalError" needs to be exported by the entry point index.d.ts
2663+
// src/plugins/data/public/index.ts:412:1 - (ae-forgotten-export) The symbol "InvalidEsIntervalFormatError" needs to be exported by the entry point index.d.ts
2664+
// src/plugins/data/public/index.ts:413:1 - (ae-forgotten-export) The symbol "Ipv4Address" needs to be exported by the entry point index.d.ts
2665+
// src/plugins/data/public/index.ts:414:1 - (ae-forgotten-export) The symbol "isDateHistogramBucketAggConfig" needs to be exported by the entry point index.d.ts
2666+
// src/plugins/data/public/index.ts:418:1 - (ae-forgotten-export) The symbol "isValidEsInterval" needs to be exported by the entry point index.d.ts
2667+
// src/plugins/data/public/index.ts:419:1 - (ae-forgotten-export) The symbol "isValidInterval" needs to be exported by the entry point index.d.ts
2668+
// src/plugins/data/public/index.ts:422:1 - (ae-forgotten-export) The symbol "parseInterval" needs to be exported by the entry point index.d.ts
2669+
// src/plugins/data/public/index.ts:423:1 - (ae-forgotten-export) The symbol "propFilter" needs to be exported by the entry point index.d.ts
2670+
// src/plugins/data/public/index.ts:426:1 - (ae-forgotten-export) The symbol "toAbsoluteDates" needs to be exported by the entry point index.d.ts
26702671
// src/plugins/data/public/query/state_sync/connect_to_query_state.ts:34:5 - (ae-forgotten-export) The symbol "FilterStateStore" needs to be exported by the entry point index.d.ts
26712672
// src/plugins/data/public/search/session/session_service.ts:42:5 - (ae-forgotten-export) The symbol "UrlGeneratorStateMapping" needs to be exported by the entry point index.d.ts
26722673

src/plugins/discover/public/application/angular/context/api/anchor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export function fetchAnchorProvider(indexPatterns, searchSource, useNewFieldsApi
3232
.setField('sort', sort);
3333
if (useNewFieldsApi) {
3434
searchSource.removeField('fieldsFromSource');
35-
searchSource.setField('fields', ['*']);
35+
searchSource.setField('fields', [{ field: '*', include_unmapped: 'true' }]);
3636
}
3737
const response = await searchSource.fetch();
3838

src/plugins/discover/public/application/angular/context/api/anchor.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ describe('context app', function () {
154154
const removeFieldsSpy = searchSourceStub.removeField.withArgs('fieldsFromSource');
155155
expect(setFieldsSpy.calledOnce).toBe(true);
156156
expect(removeFieldsSpy.calledOnce).toBe(true);
157-
expect(setFieldsSpy.firstCall.args[1]).toEqual(['*']);
157+
expect(setFieldsSpy.firstCall.args[1]).toEqual([{ field: '*', include_unmapped: 'true' }]);
158158
});
159159
});
160160
});

0 commit comments

Comments
 (0)