Skip to content

Commit

Permalink
[Mappings editor] Add support for wildcard field type (elastic#76574) (
Browse files Browse the repository at this point in the history
  • Loading branch information
alisonelizabeth authored Sep 14, 2020
1 parent af807ac commit 1a8b805
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 50 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import React, { FunctionComponent } from 'react';

import { i18n } from '@kbn/i18n';

import { documentationService } from '../../../../../services/documentation';
import { getFieldConfig } from '../../../lib';
import { UseField, Field } from '../../../shared_imports';
import { EditFieldFormRow } from '../fields/edit_field';

interface Props {
defaultToggleValue: boolean;
}

export const IgnoreAboveParameter: FunctionComponent<Props> = ({ defaultToggleValue }) => (
<EditFieldFormRow
title={i18n.translate('xpack.idxMgmt.mappingsEditor.ignoreAboveFieldTitle', {
defaultMessage: 'Set length limit',
})}
description={i18n.translate('xpack.idxMgmt.mappingsEditor.ignoreAboveFieldDescription', {
defaultMessage:
'Strings longer than this value will not be indexed. This is useful for protecting against Lucene’s term character-length limit of 8,191 UTF-8 characters.',
})}
docLink={{
text: i18n.translate('xpack.idxMgmt.mappingsEditor.ignoreAboveDocLinkText', {
defaultMessage: 'Ignore above documentation',
}),
href: documentationService.getIgnoreAboveLink(),
}}
defaultToggleValue={defaultToggleValue}
>
<UseField path="ignore_above" config={getFieldConfig('ignore_above')} component={Field} />
</EditFieldFormRow>
);
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ export * from './other_type_name_parameter';

export * from './other_type_json_parameter';

export * from './ignore_above_parameter';

export const PARAMETER_SERIALIZERS = [relationsSerializer, dynamicSerializer];

export const PARAMETER_DESERIALIZERS = [relationsDeserializer, dynamicDeserializer];
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import React from 'react';
import { i18n } from '@kbn/i18n';

import { documentationService } from '../../../../../../services/documentation';
import { NormalizedField, Field as FieldType } from '../../../../types';
import { UseField, Field } from '../../../../shared_imports';
import { getFieldConfig } from '../../../../lib';
Expand All @@ -19,6 +18,7 @@ import {
NullValueParameter,
SimilarityParameter,
SplitQueriesOnWhitespaceParameter,
IgnoreAboveParameter,
} from '../../field_parameters';
import { BasicParametersSection, EditFieldFormRow, AdvancedParametersSection } from '../edit_field';

Expand All @@ -29,6 +29,7 @@ interface Props {
const getDefaultToggleValue = (param: string, field: FieldType) => {
switch (param) {
case 'boost':
case 'ignore_above':
case 'similarity': {
return field[param] !== undefined && field[param] !== getFieldConfig(param).defaultValue;
}
Expand Down Expand Up @@ -66,28 +67,9 @@ export const FlattenedType = React.memo(({ field }: Props) => {
<UseField path="depth_limit" config={getFieldConfig('depth_limit')} component={Field} />
</EditFieldFormRow>

{/* ignore_above */}
<EditFieldFormRow
title={i18n.translate('xpack.idxMgmt.mappingsEditor.leafLengthLimitFieldTitle', {
defaultMessage: 'Set length limit',
})}
description={i18n.translate(
'xpack.idxMgmt.mappingsEditor.leafLengthLimitFieldDescription',
{
defaultMessage:
'Prevent leaf values from being indexed if they are beyond a certain length. This is useful for protecting against Lucene’s term character-length limit of 8,191 UTF-8 characters.',
}
)}
docLink={{
text: i18n.translate('xpack.idxMgmt.mappingsEditor.flattened.ignoreAboveDocLinkText', {
defaultMessage: 'Ignore above documentation',
}),
href: documentationService.getIgnoreAboveLink(),
}}
<IgnoreAboveParameter
defaultToggleValue={getDefaultToggleValue('ignore_above', field.source)}
>
<UseField path="ignore_above" config={getFieldConfig('ignore_above')} component={Field} />
</EditFieldFormRow>
/>

<SplitQueriesOnWhitespaceParameter />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { OtherType } from './other_type';
import { NestedType } from './nested_type';
import { JoinType } from './join_type';
import { RankFeatureType } from './rank_feature_type';
import { WildcardType } from './wildcard_type';

const typeToParametersFormMap: { [key in DataType]?: ComponentType<any> } = {
alias: AliasType,
Expand All @@ -54,6 +55,7 @@ const typeToParametersFormMap: { [key in DataType]?: ComponentType<any> } = {
nested: NestedType,
join: JoinType,
rank_feature: RankFeatureType,
wildcard: WildcardType,
};

export const getParametersFormForType = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
SimilarityParameter,
CopyToParameter,
SplitQueriesOnWhitespaceParameter,
IgnoreAboveParameter,
} from '../../field_parameters';
import { BasicParametersSection, EditFieldFormRow, AdvancedParametersSection } from '../edit_field';

Expand Down Expand Up @@ -79,25 +80,9 @@ export const KeywordType = ({ field }: Props) => {
<AdvancedParametersSection>
<EagerGlobalOrdinalsParameter />

{/* ignore_above */}
<EditFieldFormRow
title={i18n.translate('xpack.idxMgmt.mappingsEditor.lengthLimitFieldTitle', {
defaultMessage: 'Set length limit',
})}
description={i18n.translate('xpack.idxMgmt.mappingsEditor.lengthLimitFieldDescription', {
defaultMessage:
'Strings longer than this value will not be indexed. This is useful for protecting against Lucene’s term character-length limit of 8,191 UTF-8 characters.',
})}
docLink={{
text: i18n.translate('xpack.idxMgmt.mappingsEditor.ignoreAboveDocLinkText', {
defaultMessage: 'Ignore above documentation',
}),
href: documentationService.getIgnoreAboveLink(),
}}
<IgnoreAboveParameter
defaultToggleValue={getDefaultToggleValue('ignore_above', field.source)}
>
<UseField path="ignore_above" config={getFieldConfig('ignore_above')} component={Field} />
</EditFieldFormRow>
/>

<NormsParameter configPath="norms_keyword" />

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import React from 'react';

import { NormalizedField, Field as FieldType, ParameterName } from '../../../../types';
import { getFieldConfig } from '../../../../lib';
import { IgnoreAboveParameter } from '../../field_parameters';
import { AdvancedParametersSection } from '../edit_field';

interface Props {
field: NormalizedField;
}

const getDefaultToggleValue = (param: ParameterName, field: FieldType) => {
return field[param] !== undefined && field[param] !== getFieldConfig(param).defaultValue;
};

export const WildcardType = ({ field }: Props) => {
return (
<AdvancedParametersSection>
<IgnoreAboveParameter
defaultToggleValue={getDefaultToggleValue('ignore_above', field.source)}
/>
</AdvancedParametersSection>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,23 @@ export const TYPE_DEFINITION: { [key in DataType]: DataTypeDefinition } = {
</p>
),
},
wildcard: {
label: i18n.translate('xpack.idxMgmt.mappingsEditor.dataType.wildcardDescription', {
defaultMessage: 'Wildcard',
}),
value: 'wildcard',
documentation: {
main: '/keyword.html#wildcard-field-type',
},
description: () => (
<p>
<FormattedMessage
id="xpack.idxMgmt.mappingsEditor.dataType.wildcardLongDescription"
defaultMessage="Wildcard fields store values optimized for wildcard grep-like queries."
/>
</p>
),
},
other: {
label: i18n.translate('xpack.idxMgmt.mappingsEditor.dataType.otherDescription', {
defaultMessage: 'Other',
Expand Down Expand Up @@ -825,6 +842,7 @@ export const MAIN_TYPES: MainType[] = [
'shape',
'text',
'token_count',
'wildcard',
'other',
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export type MainType =
| 'geo_point'
| 'geo_shape'
| 'token_count'
| 'wildcard'
/**
* 'other' is a special type that only exists inside of MappingsEditor as a placeholder
* for undocumented field types.
Expand Down
5 changes: 0 additions & 5 deletions x-pack/plugins/translations/translations/ja-JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -7582,7 +7582,6 @@
"xpack.idxMgmt.mappingsEditor.fielddata.frequencyFilterPercentageFieldLabel": "パーセンテージベースの頻度範囲",
"xpack.idxMgmt.mappingsEditor.fielddata.useAbsoluteValuesFieldLabel": "絶対値の使用",
"xpack.idxMgmt.mappingsEditor.fieldsTabLabel": "マッピングされたフィールド",
"xpack.idxMgmt.mappingsEditor.flattened.ignoreAboveDocLinkText": "上記ドキュメントの無視",
"xpack.idxMgmt.mappingsEditor.formatDocLinkText": "フォーマットのドキュメンテーション",
"xpack.idxMgmt.mappingsEditor.formatFieldLabel": "フォーマット",
"xpack.idxMgmt.mappingsEditor.formatHelpText": "{dateSyntax}構文を使用し、カスタムフォーマットを指定します。",
Expand Down Expand Up @@ -7713,10 +7712,6 @@
"xpack.idxMgmt.mappingsEditor.joinType.relationshipTable.parentFieldAriaLabel": "親フィールド",
"xpack.idxMgmt.mappingsEditor.joinType.relationshipTable.removeRelationshipTooltipLabel": "関係を削除",
"xpack.idxMgmt.mappingsEditor.largestShingleSizeFieldLabel": "最大シングルサイズ",
"xpack.idxMgmt.mappingsEditor.leafLengthLimitFieldDescription": "特定の長さ以上のリーフ値のインデックスを無効化。これは、Luceneの文字制限(8,191 UTF-8 文字)に対する保護に役立ちます。",
"xpack.idxMgmt.mappingsEditor.leafLengthLimitFieldTitle": "長さ制限の設定",
"xpack.idxMgmt.mappingsEditor.lengthLimitFieldDescription": "この値よりも長い文字列はインデックスされません。これは、Luceneの文字制限(8,191 UTF-8 文字)に対する保護に役立ちます。",
"xpack.idxMgmt.mappingsEditor.lengthLimitFieldTitle": "長さ制限の設定",
"xpack.idxMgmt.mappingsEditor.loadFromJsonButtonLabel": "JSONの読み込み",
"xpack.idxMgmt.mappingsEditor.loadJsonModal.acceptWarningLabel": "読み込みの続行",
"xpack.idxMgmt.mappingsEditor.loadJsonModal.cancelButtonLabel": "キャンセル",
Expand Down
5 changes: 0 additions & 5 deletions x-pack/plugins/translations/translations/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -7585,7 +7585,6 @@
"xpack.idxMgmt.mappingsEditor.fielddata.frequencyFilterPercentageFieldLabel": "基于百分比的频率范围",
"xpack.idxMgmt.mappingsEditor.fielddata.useAbsoluteValuesFieldLabel": "使用绝对值",
"xpack.idxMgmt.mappingsEditor.fieldsTabLabel": "已映射字段",
"xpack.idxMgmt.mappingsEditor.flattened.ignoreAboveDocLinkText": "“忽略上述”文档",
"xpack.idxMgmt.mappingsEditor.formatDocLinkText": "“格式”文档",
"xpack.idxMgmt.mappingsEditor.formatFieldLabel": "格式",
"xpack.idxMgmt.mappingsEditor.formatHelpText": "使用 {dateSyntax} 语法指定定制格式。",
Expand Down Expand Up @@ -7716,10 +7715,6 @@
"xpack.idxMgmt.mappingsEditor.joinType.relationshipTable.parentFieldAriaLabel": "父项字段",
"xpack.idxMgmt.mappingsEditor.joinType.relationshipTable.removeRelationshipTooltipLabel": "移除关系",
"xpack.idxMgmt.mappingsEditor.largestShingleSizeFieldLabel": "最大瓦形大小",
"xpack.idxMgmt.mappingsEditor.leafLengthLimitFieldDescription": "如果叶值超过一定长度,则阻止叶值索引。这用于防止超出 Lucene 的字词字符长度限制,即 8,191 个 UTF-8 字符。",
"xpack.idxMgmt.mappingsEditor.leafLengthLimitFieldTitle": "设置长度限制",
"xpack.idxMgmt.mappingsEditor.lengthLimitFieldDescription": "将不索引超过此值的字符串。这用于防止超出 Lucene 的字词字符长度限制,即 8,191 个 UTF-8 字符。",
"xpack.idxMgmt.mappingsEditor.lengthLimitFieldTitle": "设置长度限制",
"xpack.idxMgmt.mappingsEditor.loadFromJsonButtonLabel": "加载 JSON",
"xpack.idxMgmt.mappingsEditor.loadJsonModal.acceptWarningLabel": "继续加载",
"xpack.idxMgmt.mappingsEditor.loadJsonModal.cancelButtonLabel": "取消",
Expand Down

0 comments on commit 1a8b805

Please sign in to comment.