Skip to content

Commit fa0e809

Browse files
kibanamachineqn895
andauthored
[ML] Fix Index Data Visualizer error if index pattern has histogram field type (#104553) (#104919)
* [ML] Add NON_AGGREGATABLE_FIELD_TYPES, add icon type * Fix types * Add histogram icon, fix types showing for hidden fields Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Quynh Nguyen <43350163+qn895@users.noreply.github.com>
1 parent f29056d commit fa0e809

File tree

7 files changed

+47
-42
lines changed

7 files changed

+47
-42
lines changed

x-pack/plugins/data_visualizer/common/constants.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
* 2.0.
66
*/
77

8+
import { KBN_FIELD_TYPES } from '../../../../src/plugins/data/common';
9+
810
export const UI_SETTING_MAX_FILE_SIZE = 'fileUpload:maxFileSize';
911

1012
export const MB = Math.pow(2, 20);
@@ -27,7 +29,26 @@ export const JOB_FIELD_TYPES = {
2729
KEYWORD: 'keyword',
2830
NUMBER: 'number',
2931
TEXT: 'text',
32+
HISTOGRAM: 'histogram',
3033
UNKNOWN: 'unknown',
3134
} as const;
3235

36+
export const JOB_FIELD_TYPES_OPTIONS = {
37+
[JOB_FIELD_TYPES.BOOLEAN]: { name: 'Boolean', icon: 'tokenBoolean' },
38+
[JOB_FIELD_TYPES.DATE]: { name: 'Date', icon: 'tokenDate' },
39+
[JOB_FIELD_TYPES.GEO_POINT]: { name: 'Geo point', icon: 'tokenGeo' },
40+
[JOB_FIELD_TYPES.GEO_SHAPE]: { name: 'Geo shape', icon: 'tokenGeo' },
41+
[JOB_FIELD_TYPES.IP]: { name: 'IP address', icon: 'tokenIP' },
42+
[JOB_FIELD_TYPES.KEYWORD]: { name: 'Keyword', icon: 'tokenKeyword' },
43+
[JOB_FIELD_TYPES.NUMBER]: { name: 'Number', icon: 'tokenNumber' },
44+
[JOB_FIELD_TYPES.TEXT]: { name: 'Text', icon: 'tokenString' },
45+
[JOB_FIELD_TYPES.HISTOGRAM]: { name: 'Histogram', icon: 'tokenNumber' },
46+
[JOB_FIELD_TYPES.UNKNOWN]: { name: 'Unknown' },
47+
};
48+
3349
export const OMIT_FIELDS: string[] = ['_source', '_type', '_index', '_id', '_version', '_score'];
50+
51+
export const NON_AGGREGATABLE_FIELD_TYPES = new Set<string>([
52+
KBN_FIELD_TYPES.GEO_SHAPE,
53+
KBN_FIELD_TYPES.HISTOGRAM,
54+
]);

x-pack/plugins/data_visualizer/public/application/common/components/field_type_icon/field_type_icon.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ export const FieldTypeIcon: FC<FieldTypeIconProps> = ({
7272
iconType = 'tokenNumber';
7373
color = fieldName !== undefined ? 'euiColorVis1' : 'euiColorVis2';
7474
break;
75+
case JOB_FIELD_TYPES.HISTOGRAM:
76+
iconType = 'tokenHistogram';
77+
color = 'euiColorVis7';
7578
case JOB_FIELD_TYPES.UNKNOWN:
7679
// Use defaults
7780
break;

x-pack/plugins/data_visualizer/public/application/common/components/field_types_filter/field_types_filter.tsx

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,7 @@ import type {
1414
FileBasedUnknownFieldVisConfig,
1515
} from '../stats_table/types/field_vis_config';
1616
import { FieldTypeIcon } from '../field_type_icon';
17-
import { JOB_FIELD_TYPES } from '../../../../../common';
18-
19-
const JOB_FIELD_TYPES_OPTIONS = {
20-
[JOB_FIELD_TYPES.BOOLEAN]: { name: 'Boolean', icon: 'tokenBoolean' },
21-
[JOB_FIELD_TYPES.DATE]: { name: 'Date', icon: 'tokenDate' },
22-
[JOB_FIELD_TYPES.GEO_POINT]: { name: 'Geo point', icon: 'tokenGeo' },
23-
[JOB_FIELD_TYPES.GEO_SHAPE]: { name: 'Geo shape', icon: 'tokenGeo' },
24-
[JOB_FIELD_TYPES.IP]: { name: 'IP address', icon: 'tokenIP' },
25-
[JOB_FIELD_TYPES.KEYWORD]: { name: 'Keyword', icon: 'tokenKeyword' },
26-
[JOB_FIELD_TYPES.NUMBER]: { name: 'Number', icon: 'tokenNumber' },
27-
[JOB_FIELD_TYPES.TEXT]: { name: 'Text', icon: 'tokenString' },
28-
[JOB_FIELD_TYPES.UNKNOWN]: { name: 'Unknown' },
29-
};
17+
import { JOB_FIELD_TYPES_OPTIONS } from '../../../../../common';
3018

3119
interface Props {
3220
fields: Array<FileBasedFieldVisConfig | FileBasedUnknownFieldVisConfig>;

x-pack/plugins/data_visualizer/public/application/common/util/field_types_utils.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ export function kbnTypeToJobType(field: IndexPatternField) {
7878
case KBN_FIELD_TYPES.GEO_SHAPE:
7979
type = JOB_FIELD_TYPES.GEO_SHAPE;
8080
break;
81+
case KBN_FIELD_TYPES.HISTOGRAM:
82+
type = JOB_FIELD_TYPES.HISTOGRAM;
83+
break;
8184

8285
default:
8386
break;

x-pack/plugins/data_visualizer/public/application/index_data_visualizer/components/index_data_visualizer_view/index_data_visualizer_view.tsx

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ import { useDataVisualizerKibana } from '../../../kibana_context';
5656
import { FieldCountPanel } from '../../../common/components/field_count_panel';
5757
import { DocumentCountContent } from '../../../common/components/document_count_content';
5858
import { DataLoader } from '../../data_loader/data_loader';
59-
import { JOB_FIELD_TYPES } from '../../../../../common';
59+
import { JOB_FIELD_TYPES, OMIT_FIELDS } from '../../../../../common';
6060
import { useTimefilter } from '../../hooks/use_time_filter';
6161
import { kbnTypeToJobType } from '../../../common/util/field_types_utils';
6262
import { SearchPanel } from '../search_panel';
@@ -204,18 +204,21 @@ export const IndexDataVisualizerView: FC<IndexDataVisualizerViewProps> = (dataVi
204204
}
205205
}, [currentIndexPattern, toasts]);
206206

207-
// Obtain the list of non metric field types which appear in the index pattern.
208-
let indexedFieldTypes: JobFieldType[] = [];
209207
const indexPatternFields: IndexPatternField[] = currentIndexPattern.fields;
210-
indexPatternFields.forEach((field) => {
211-
if (field.scripted !== true) {
212-
const dataVisualizerType: JobFieldType | undefined = kbnTypeToJobType(field);
213-
if (dataVisualizerType !== undefined && !indexedFieldTypes.includes(dataVisualizerType)) {
214-
indexedFieldTypes.push(dataVisualizerType);
208+
209+
const fieldTypes = useMemo(() => {
210+
// Obtain the list of non metric field types which appear in the index pattern.
211+
const indexedFieldTypes: JobFieldType[] = [];
212+
indexPatternFields.forEach((field) => {
213+
if (!OMIT_FIELDS.includes(field.name) && field.scripted !== true) {
214+
const dataVisualizerType: JobFieldType | undefined = kbnTypeToJobType(field);
215+
if (dataVisualizerType !== undefined && !indexedFieldTypes.includes(dataVisualizerType)) {
216+
indexedFieldTypes.push(dataVisualizerType);
217+
}
215218
}
216-
}
217-
});
218-
indexedFieldTypes = indexedFieldTypes.sort();
219+
});
220+
return indexedFieldTypes.sort();
221+
}, [indexPatternFields]);
219222

220223
const defaults = getDefaultPageState();
221224

@@ -859,7 +862,7 @@ export const IndexDataVisualizerView: FC<IndexDataVisualizerViewProps> = (dataVi
859862
samplerShardSize={samplerShardSize}
860863
setSamplerShardSize={setSamplerShardSize}
861864
overallStats={overallStats}
862-
indexedFieldTypes={indexedFieldTypes}
865+
indexedFieldTypes={fieldTypes}
863866
setVisibleFieldTypes={setVisibleFieldTypes}
864867
visibleFieldTypes={visibleFieldTypes}
865868
visibleFieldNames={visibleFieldNames}

x-pack/plugins/data_visualizer/public/application/index_data_visualizer/components/search_panel/field_type_filter.tsx

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,18 @@
88
import React, { FC, useMemo } from 'react';
99
import { EuiFlexGroup, EuiFlexItem } from '@elastic/eui';
1010
import { i18n } from '@kbn/i18n';
11-
import { JOB_FIELD_TYPES, JobFieldType } from '../../../../../common';
11+
import { JOB_FIELD_TYPES_OPTIONS, JobFieldType } from '../../../../../common';
1212
import { FieldTypeIcon } from '../../../common/components/field_type_icon';
1313
import { MultiSelectPicker, Option } from '../../../common/components/multi_select_picker';
1414

15-
const ML_JOB_FIELD_TYPES_OPTIONS = {
16-
[JOB_FIELD_TYPES.BOOLEAN]: { name: 'Boolean', icon: 'tokenBoolean' },
17-
[JOB_FIELD_TYPES.DATE]: { name: 'Date', icon: 'tokenDate' },
18-
[JOB_FIELD_TYPES.GEO_POINT]: { name: 'Geo point', icon: 'tokenGeo' },
19-
[JOB_FIELD_TYPES.GEO_SHAPE]: { name: 'Geo shape', icon: 'tokenGeo' },
20-
[JOB_FIELD_TYPES.IP]: { name: 'IP address', icon: 'tokenIP' },
21-
[JOB_FIELD_TYPES.KEYWORD]: { name: 'Keyword', icon: 'tokenKeyword' },
22-
[JOB_FIELD_TYPES.NUMBER]: { name: 'Number', icon: 'tokenNumber' },
23-
[JOB_FIELD_TYPES.TEXT]: { name: 'Text', icon: 'tokenString' },
24-
[JOB_FIELD_TYPES.UNKNOWN]: { name: 'Unknown' },
25-
};
26-
2715
export const DatavisualizerFieldTypeFilter: FC<{
2816
indexedFieldTypes: JobFieldType[];
2917
setVisibleFieldTypes(q: string[]): void;
3018
visibleFieldTypes: string[];
3119
}> = ({ indexedFieldTypes, setVisibleFieldTypes, visibleFieldTypes }) => {
3220
const options: Option[] = useMemo(() => {
3321
return indexedFieldTypes.map((indexedFieldName) => {
34-
const item = ML_JOB_FIELD_TYPES_OPTIONS[indexedFieldName];
22+
const item = JOB_FIELD_TYPES_OPTIONS[indexedFieldName];
3523

3624
return {
3725
value: indexedFieldName,

x-pack/plugins/data_visualizer/public/application/index_data_visualizer/data_loader/data_loader.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ import { CoreSetup } from 'kibana/public';
1010
import { estypes } from '@elastic/elasticsearch';
1111
import { i18n } from '@kbn/i18n';
1212
import { IndexPattern } from '../../../../../../../src/plugins/data/common/index_patterns/index_patterns';
13-
import { KBN_FIELD_TYPES } from '../../../../../../../src/plugins/data/common';
14-
import { OMIT_FIELDS } from '../../../../common/constants';
13+
import { NON_AGGREGATABLE_FIELD_TYPES, OMIT_FIELDS } from '../../../../common/constants';
1514
import { FieldRequestConfig } from '../../../../common/types';
1615
import { getVisualizerFieldStats, getVisualizerOverallStats } from '../services/visualizer_stats';
1716

@@ -49,7 +48,7 @@ export class DataLoader {
4948
this._indexPattern.fields.forEach((field) => {
5049
const fieldName = field.displayName !== undefined ? field.displayName : field.name;
5150
if (this.isDisplayField(fieldName) === true) {
52-
if (field.aggregatable === true && field.type !== KBN_FIELD_TYPES.GEO_SHAPE) {
51+
if (field.aggregatable === true && !NON_AGGREGATABLE_FIELD_TYPES.has(field.type)) {
5352
aggregatableFields.push(field.name);
5453
} else {
5554
nonAggregatableFields.push(field.name);

0 commit comments

Comments
 (0)