Skip to content

Commit

Permalink
[ML] Transforms: Fixes terms aggregation support in wizard. (#151879)
Browse files Browse the repository at this point in the history
The mapping to allow aggregating with the `terms` aggregation was
missing on some field types. This PR fixes the mapping to be in line with the field support defined
in ES docs (https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html).
  • Loading branch information
walterra committed Feb 24, 2023
1 parent db1c79a commit ee3e5eb
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 8 deletions.
7 changes: 6 additions & 1 deletion x-pack/plugins/transform/public/app/common/pivot_aggs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ export const TERMS_AGG_DEFAULT_SIZE = 10;

export const pivotAggsFieldSupport = {
[KBN_FIELD_TYPES.ATTACHMENT]: [PIVOT_SUPPORTED_AGGS.VALUE_COUNT, PIVOT_SUPPORTED_AGGS.FILTER],
[KBN_FIELD_TYPES.BOOLEAN]: [PIVOT_SUPPORTED_AGGS.VALUE_COUNT, PIVOT_SUPPORTED_AGGS.FILTER],
[KBN_FIELD_TYPES.BOOLEAN]: [
PIVOT_SUPPORTED_AGGS.VALUE_COUNT,
PIVOT_SUPPORTED_AGGS.FILTER,
PIVOT_SUPPORTED_AGGS.TERMS,
],
[KBN_FIELD_TYPES.DATE]: [
PIVOT_SUPPORTED_AGGS.MAX,
PIVOT_SUPPORTED_AGGS.MIN,
Expand All @@ -58,6 +62,7 @@ export const pivotAggsFieldSupport = {
PIVOT_SUPPORTED_AGGS.SUM,
PIVOT_SUPPORTED_AGGS.VALUE_COUNT,
PIVOT_SUPPORTED_AGGS.FILTER,
PIVOT_SUPPORTED_AGGS.TERMS,
PIVOT_SUPPORTED_AGGS.TOP_METRICS,
],
[KBN_FIELD_TYPES.STRING]: [
Expand Down
7 changes: 5 additions & 2 deletions x-pack/plugins/transform/public/app/common/pivot_group_by.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,16 @@ export type PivotSupportedGroupByAggsWithInterval =

export const pivotGroupByFieldSupport = {
[KBN_FIELD_TYPES.ATTACHMENT]: [],
[KBN_FIELD_TYPES.BOOLEAN]: [],
[KBN_FIELD_TYPES.BOOLEAN]: [PIVOT_SUPPORTED_GROUP_BY_AGGS.TERMS],
[KBN_FIELD_TYPES.DATE]: [PIVOT_SUPPORTED_GROUP_BY_AGGS.DATE_HISTOGRAM],
[KBN_FIELD_TYPES.GEO_POINT]: [],
[KBN_FIELD_TYPES.GEO_SHAPE]: [],
[KBN_FIELD_TYPES.IP]: [PIVOT_SUPPORTED_GROUP_BY_AGGS.TERMS],
[KBN_FIELD_TYPES.MURMUR3]: [],
[KBN_FIELD_TYPES.NUMBER]: [PIVOT_SUPPORTED_GROUP_BY_AGGS.HISTOGRAM],
[KBN_FIELD_TYPES.NUMBER]: [
PIVOT_SUPPORTED_GROUP_BY_AGGS.HISTOGRAM,
PIVOT_SUPPORTED_GROUP_BY_AGGS.TERMS,
],
[KBN_FIELD_TYPES.STRING]: [PIVOT_SUPPORTED_GROUP_BY_AGGS.TERMS],
[KBN_FIELD_TYPES._SOURCE]: [],
[KBN_FIELD_TYPES.UNKNOWN]: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { getPivotDropdownOptions } from '.';
import { DataView } from '@kbn/data-views-plugin/public';
import type { DataView } from '@kbn/data-views-plugin/public';
import { FilterAggForm } from './filter_agg/components';
import type { RuntimeField } from '@kbn/data-views-plugin/common';
import { PercentilesAggForm } from './percentiles_agg/percentiles_form_component';
Expand All @@ -31,8 +31,8 @@ describe('Transform: Define Pivot Common', () => {
} as DataView;

const options = getPivotDropdownOptions(dataView);

expect(options).toMatchObject({
fields: [{ name: ' the-f[i]e>ld ', type: 'number' }],
aggOptions: [
{
label: ' the-f[i]e>ld ',
Expand All @@ -45,8 +45,10 @@ describe('Transform: Define Pivot Common', () => {
{ label: 'sum( the-f[i]e>ld )' },
{ label: 'value_count( the-f[i]e>ld )' },
{ label: 'filter( the-f[i]e>ld )' },
{ label: 'terms( the-f[i]e>ld )' },
{ label: 'top_metrics( the-f[i]e>ld )' },
],
field: { id: ' the-f[i]e>ld ', type: 'number' },
},
],
aggOptionsData: {
Expand Down Expand Up @@ -101,8 +103,29 @@ describe('Transform: Define Pivot Common', () => {
aggName: 'the-field.value_count',
dropDownName: 'value_count( the-f[i]e>ld )',
},
'terms( the-f[i]e>ld )': {
agg: 'terms',
field: ' the-f[i]e>ld ',
aggName: 'the-field.terms',
dropDownName: 'terms( the-f[i]e>ld )',
isSubAggsSupported: false,
isMultiField: false,
aggConfig: { size: 10 },
},
'top_metrics( the-f[i]e>ld )': {
agg: 'top_metrics',
field: ' the-f[i]e>ld ',
aggName: 'top_metrics',
dropDownName: 'top_metrics( the-f[i]e>ld )',
isSubAggsSupported: false,
isMultiField: true,
aggConfig: {},
},
},
groupByOptions: [{ label: 'histogram( the-f[i]e>ld )' }],
groupByOptions: [
{ label: 'histogram( the-f[i]e>ld )', field: { id: ' the-f[i]e>ld ', type: 'number' } },
{ label: 'terms( the-f[i]e>ld )', field: { id: ' the-f[i]e>ld ', type: 'number' } },
],
groupByOptionsData: {
'histogram( the-f[i]e>ld )': {
agg: 'histogram',
Expand All @@ -111,6 +134,12 @@ describe('Transform: Define Pivot Common', () => {
dropDownName: 'histogram( the-f[i]e>ld )',
interval: '10',
},
'terms( the-f[i]e>ld )': {
agg: 'terms',
aggName: 'the-field',
dropDownName: 'terms( the-f[i]e>ld )',
field: ' the-f[i]e>ld ',
},
},
});

Expand All @@ -124,6 +153,10 @@ describe('Transform: Define Pivot Common', () => {
};
const optionsWithRuntimeFields = getPivotDropdownOptions(dataView, runtimeMappings);
expect(optionsWithRuntimeFields).toMatchObject({
fields: [
{ name: ' the-f[i]e>ld ', type: 'number' },
{ name: 'rt_bytes_bigger', type: 'number' },
],
aggOptions: [
{
label: ' the-f[i]e>ld ',
Expand All @@ -136,8 +169,10 @@ describe('Transform: Define Pivot Common', () => {
{ label: 'sum( the-f[i]e>ld )' },
{ label: 'value_count( the-f[i]e>ld )' },
{ label: 'filter( the-f[i]e>ld )' },
{ label: 'terms( the-f[i]e>ld )' },
{ label: 'top_metrics( the-f[i]e>ld )' },
],
field: { id: ' the-f[i]e>ld ', type: 'number' },
},
{
label: 'rt_bytes_bigger',
Expand All @@ -150,8 +185,10 @@ describe('Transform: Define Pivot Common', () => {
{ label: 'sum(rt_bytes_bigger)' },
{ label: 'value_count(rt_bytes_bigger)' },
{ label: 'filter(rt_bytes_bigger)' },
{ label: 'terms(rt_bytes_bigger)' },
{ label: 'top_metrics(rt_bytes_bigger)' },
],
field: { id: 'rt_bytes_bigger', type: 'number' },
},
],
aggOptionsData: {
Expand Down Expand Up @@ -207,6 +244,24 @@ describe('Transform: Define Pivot Common', () => {
isSubAggsSupported: true,
AggFormComponent: FilterAggForm,
},
'terms( the-f[i]e>ld )': {
agg: 'terms',
aggName: 'the-field.terms',
dropDownName: 'terms( the-f[i]e>ld )',
field: ' the-f[i]e>ld ',
isSubAggsSupported: false,
isMultiField: false,
aggConfig: { size: 10 },
},
'top_metrics( the-f[i]e>ld )': {
agg: 'top_metrics',
aggName: 'top_metrics',
dropDownName: 'top_metrics( the-f[i]e>ld )',
field: ' the-f[i]e>ld ',
isSubAggsSupported: false,
isMultiField: true,
aggConfig: {},
},
'avg(rt_bytes_bigger)': {
agg: 'avg',
aggName: 'rt_bytes_bigger.avg',
Expand Down Expand Up @@ -259,10 +314,30 @@ describe('Transform: Define Pivot Common', () => {
isSubAggsSupported: true,
AggFormComponent: FilterAggForm,
},
'terms(rt_bytes_bigger)': {
agg: 'terms',
field: 'rt_bytes_bigger',
aggName: 'rt_bytes_bigger.terms',
dropDownName: 'terms(rt_bytes_bigger)',
isSubAggsSupported: false,
isMultiField: false,
aggConfig: { size: 10 },
},
'top_metrics(rt_bytes_bigger)': {
agg: 'top_metrics',
field: 'rt_bytes_bigger',
aggName: 'top_metrics',
dropDownName: 'top_metrics(rt_bytes_bigger)',
isSubAggsSupported: false,
isMultiField: true,
aggConfig: {},
},
},
groupByOptions: [
{ label: 'histogram( the-f[i]e>ld )' },
{ label: 'histogram(rt_bytes_bigger)' },
{ label: 'histogram( the-f[i]e>ld )', field: { id: ' the-f[i]e>ld ', type: 'number' } },
{ label: 'terms( the-f[i]e>ld )', field: { id: ' the-f[i]e>ld ', type: 'number' } },
{ label: 'histogram(rt_bytes_bigger)', field: { id: 'rt_bytes_bigger', type: 'number' } },
{ label: 'terms(rt_bytes_bigger)', field: { id: 'rt_bytes_bigger', type: 'number' } },
],
groupByOptionsData: {
'histogram( the-f[i]e>ld )': {
Expand All @@ -272,13 +347,25 @@ describe('Transform: Define Pivot Common', () => {
field: ' the-f[i]e>ld ',
interval: '10',
},
'terms( the-f[i]e>ld )': {
agg: 'terms',
field: ' the-f[i]e>ld ',
aggName: 'the-field',
dropDownName: 'terms( the-f[i]e>ld )',
},
'histogram(rt_bytes_bigger)': {
agg: 'histogram',
aggName: 'rt_bytes_bigger',
dropDownName: 'histogram(rt_bytes_bigger)',
field: 'rt_bytes_bigger',
interval: '10',
},
'terms(rt_bytes_bigger)': {
agg: 'terms',
field: 'rt_bytes_bigger',
aggName: 'rt_bytes_bigger',
dropDownName: 'terms(rt_bytes_bigger)',
},
},
});
});
Expand Down

0 comments on commit ee3e5eb

Please sign in to comment.