mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
[lens] significant terms convert to lens (#159580)
Part of https://github.com/elastic/kibana/issues/154307
Update convert to lens functionality to support significant terms
aggregation
<img width="500" alt="Screen Shot 2023-06-13 at 8 58 09 AM"
src="949199ee
-24e2-45d0-84b1-512698abecb4">
---------
Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Stratoula Kalafateli <efstratia.kalafateli@elastic.co>
This commit is contained in:
parent
24e449e952
commit
57a17751c3
4 changed files with 63 additions and 5 deletions
|
@ -21,6 +21,7 @@ import { getFieldNameFromField, getLabel, isSchemaConfig } from '../utils';
|
|||
|
||||
export type BucketAggs =
|
||||
| BUCKET_TYPES.TERMS
|
||||
| BUCKET_TYPES.SIGNIFICANT_TERMS
|
||||
| BUCKET_TYPES.DATE_HISTOGRAM
|
||||
| BUCKET_TYPES.FILTERS
|
||||
| BUCKET_TYPES.RANGE
|
||||
|
@ -28,6 +29,7 @@ export type BucketAggs =
|
|||
|
||||
const SUPPORTED_BUCKETS: string[] = [
|
||||
BUCKET_TYPES.TERMS,
|
||||
BUCKET_TYPES.SIGNIFICANT_TERMS,
|
||||
BUCKET_TYPES.DATE_HISTOGRAM,
|
||||
BUCKET_TYPES.FILTERS,
|
||||
BUCKET_TYPES.RANGE,
|
||||
|
@ -64,6 +66,7 @@ export const getBucketColumns = (
|
|||
case BUCKET_TYPES.HISTOGRAM:
|
||||
return convertToRangeColumn(agg.aggId ?? '', agg.aggParams, label, dataView, isSplit);
|
||||
case BUCKET_TYPES.TERMS:
|
||||
case BUCKET_TYPES.SIGNIFICANT_TERMS:
|
||||
const fieldName = getFieldNameFromField(agg.aggParams.field);
|
||||
if (!fieldName) {
|
||||
return null;
|
||||
|
|
|
@ -244,6 +244,40 @@ describe('convertToDateHistogramColumn', () => {
|
|||
mockConvertMetricToColumns.mockReturnValue(metricColumns);
|
||||
},
|
||||
],
|
||||
[
|
||||
'significant terms column',
|
||||
[
|
||||
aggId,
|
||||
{
|
||||
agg: {
|
||||
aggType: BUCKET_TYPES.SIGNIFICANT_TERMS,
|
||||
aggParams: {
|
||||
field: stubLogstashDataView.fields[0].name,
|
||||
size: 5,
|
||||
},
|
||||
} as SchemaConfig<BUCKET_TYPES.SIGNIFICANT_TERMS>,
|
||||
dataView: stubLogstashDataView,
|
||||
aggs,
|
||||
metricColumns,
|
||||
visType,
|
||||
},
|
||||
'',
|
||||
false,
|
||||
],
|
||||
{
|
||||
operationType: 'terms',
|
||||
sourceField: stubLogstashDataView.fields[0].name,
|
||||
isBucketed: true,
|
||||
params: {
|
||||
size: 5,
|
||||
include: [],
|
||||
exclude: [],
|
||||
orderBy: { type: 'significant' },
|
||||
orderDirection: 'desc',
|
||||
},
|
||||
},
|
||||
() => {},
|
||||
],
|
||||
])('should return %s', (_, input, expected, actions) => {
|
||||
actions();
|
||||
if (expected === null) {
|
||||
|
|
|
@ -89,20 +89,34 @@ export const convertToTermsParams = ({
|
|||
aggs,
|
||||
metricColumns,
|
||||
visType,
|
||||
}: CommonBucketConverterArgs<BUCKET_TYPES.TERMS>): TermsParams | null => {
|
||||
}: CommonBucketConverterArgs<
|
||||
BUCKET_TYPES.TERMS | BUCKET_TYPES.SIGNIFICANT_TERMS
|
||||
>): TermsParams | null => {
|
||||
if (!agg.aggParams) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const size = agg.aggParams.size ?? 10;
|
||||
const exclude = agg.aggParams.exclude ? filterOutEmptyValues(agg.aggParams.exclude) : [];
|
||||
const include = agg.aggParams.include ? filterOutEmptyValues(agg.aggParams.include) : [];
|
||||
|
||||
if (agg.aggType === BUCKET_TYPES.SIGNIFICANT_TERMS) {
|
||||
return {
|
||||
size: agg.aggParams.size ?? 10,
|
||||
orderDirection: 'desc',
|
||||
include,
|
||||
exclude,
|
||||
orderBy: { type: 'significant' },
|
||||
};
|
||||
}
|
||||
|
||||
const orderByWithAgg = getOrderByWithAgg({ agg, dataView, aggs, metricColumns, visType });
|
||||
if (orderByWithAgg === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const exclude = agg.aggParams.exclude ? filterOutEmptyValues(agg.aggParams.exclude) : [];
|
||||
const include = agg.aggParams.include ? filterOutEmptyValues(agg.aggParams.include) : [];
|
||||
return {
|
||||
size: agg.aggParams.size ?? 10,
|
||||
size,
|
||||
include,
|
||||
exclude,
|
||||
includeIsRegex: Boolean(include.length && agg.aggParams.includeIsRegex),
|
||||
|
@ -117,7 +131,13 @@ export const convertToTermsParams = ({
|
|||
|
||||
export const convertToTermsColumn = (
|
||||
aggId: string,
|
||||
{ agg, dataView, aggs, metricColumns, visType }: CommonBucketConverterArgs<BUCKET_TYPES.TERMS>,
|
||||
{
|
||||
agg,
|
||||
dataView,
|
||||
aggs,
|
||||
metricColumns,
|
||||
visType,
|
||||
}: CommonBucketConverterArgs<BUCKET_TYPES.TERMS | BUCKET_TYPES.SIGNIFICANT_TERMS>,
|
||||
label: string,
|
||||
isSplit: boolean
|
||||
): TermsColumn | null => {
|
||||
|
|
|
@ -30,6 +30,7 @@ export interface TermsParams extends FormatParams {
|
|||
orderBy:
|
||||
| { type: 'alphabetical'; fallback?: boolean }
|
||||
| { type: 'rare'; maxDocCount: number }
|
||||
| { type: 'significant' }
|
||||
| { type: 'column'; columnId: string }
|
||||
| { type: 'custom' };
|
||||
orderAgg?: Column;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue