Skip to content

Commit

Permalink
add support for point field type
Browse files Browse the repository at this point in the history
  • Loading branch information
alisonelizabeth committed Sep 15, 2020
1 parent d190a2a commit 8d5fe94
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,19 @@ import { i18n } from '@kbn/i18n';

import { EditFieldFormRow } from '../fields/edit_field';

export const IgnoreZValueParameter = () => (
export const IgnoreZValueParameter = ({ description }: { description?: string }) => (
<EditFieldFormRow
title={i18n.translate('xpack.idxMgmt.mappingsEditor.ignoreZValueFieldTitle', {
defaultMessage: 'Ignore Z value',
})}
description={i18n.translate('xpack.idxMgmt.mappingsEditor.ignoredZValueFieldDescription', {
defaultMessage:
'Three dimension points will be accepted, but only latitude and longitude values will be indexed; the third dimension is ignored.',
})}
description={
description
? description
: i18n.translate('xpack.idxMgmt.mappingsEditor.ignoredZValueFieldDescription', {
defaultMessage:
'Three dimension points will be accepted, but only latitude and longitude values will be indexed; the third dimension is ignored.',
})
}
formFieldPath="ignore_z_value"
/>
);
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { NestedType } from './nested_type';
import { JoinType } from './join_type';
import { RankFeatureType } from './rank_feature_type';
import { WildcardType } from './wildcard_type';
import { PointType } from './point_type';

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

export const getParametersFormForType = (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* 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 { NormalizedField, Field as FieldType, ParameterName } from '../../../../types';
import { UseField, TextAreaField } from '../../../../shared_imports';
import { getFieldConfig } from '../../../../lib';
import {
IgnoreMalformedParameter,
IgnoreZValueParameter,
NullValueParameter,
} from '../../field_parameters';
import { AdvancedParametersSection, BasicParametersSection } from '../edit_field';

interface Props {
field: NormalizedField;
}

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

export const PointType: FunctionComponent<Props> = ({ field }) => {
return (
<>
<BasicParametersSection>
<IgnoreMalformedParameter
description={i18n.translate(
'xpack.idxMgmt.mappingsEditor.point.ignoreMalformedFieldDescription',
{
defaultMessage:
'By default, documents that contain malformed points are not indexed. If enabled, these documents are indexed, but fields with malformed points are filtered out. Be careful: if too many documents are indexed this way, queries on the field become meaningless.',
}
)}
/>
</BasicParametersSection>

<AdvancedParametersSection>
<IgnoreZValueParameter
description={i18n.translate(
'xpack.idxMgmt.mappingsEditor.point.ignoreZValueFieldDescription',
{
defaultMessage:
'Three dimension points will be accepted, but only x and y values will be indexed; the third dimension is ignored.',
}
)}
/>

<NullValueParameter
defaultToggleValue={getDefaultToggleValue('null_value', field.source)}
description={i18n.translate(
'xpack.idxMgmt.mappingsEditor.point.nullValueFieldDescription',
{
defaultMessage:
'Replace explicit null values with a point value so that it can be indexed and searched.',
}
)}
>
<UseField
path="null_value"
component={TextAreaField}
config={getFieldConfig('null_value_point')}
/>
</NullValueParameter>
</AdvancedParametersSection>
</>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,26 @@ export const TYPE_DEFINITION: { [key in DataType]: DataTypeDefinition } = {
</p>
),
},
point: {
label: i18n.translate('xpack.idxMgmt.mappingsEditor.dataType.pointDescription', {
defaultMessage: 'Point',
}),
value: 'point',
documentation: {
main: '/point.html',
},
description: () => (
<p>
<FormattedMessage
id="xpack.idxMgmt.mappingsEditor.dataType.pointLongDescription"
defaultMessage="Point fields enable searching of {code} pairs that fall in a 2-dimensional planar coordinate system."
values={{
code: <EuiCode inline>{'x,y'}</EuiCode>,
}}
/>
</p>
),
},
wildcard: {
label: i18n.translate('xpack.idxMgmt.mappingsEditor.dataType.wildcardDescription', {
defaultMessage: 'Wildcard',
Expand Down Expand Up @@ -843,6 +863,7 @@ export const MAIN_TYPES: MainType[] = [
'text',
'token_count',
'wildcard',
'point',
'other',
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,50 @@ export const PARAMETERS_DEFINITION: { [key in ParameterName]: ParameterDefinitio
},
schema: t.any,
},
null_value_point: {
fieldConfig: {
defaultValue: '',
label: nullValueLabel,
helpText: () => (
<FormattedMessage
id="xpack.idxMgmt.mappingsEditor.parameters.pointNullValueHelpText"
defaultMessage="Points can be expressed as an object, string, array or {docsLink} POINT."
values={{
docsLink: (
<EuiLink href={documentationService.getWellKnownTextLink()} target="_blank">
{i18n.translate(
'xpack.idxMgmt.mappingsEditor.parameters.pointWellKnownTextDocumentationLink',
{
defaultMessage: 'Well-Known Text',
}
)}
</EuiLink>
),
}}
/>
),
validations: [
{
validator: nullValueValidateEmptyField,
},
],
deserializer: (value: any) => {
if (value === '') {
return value;
}
return JSON.stringify(value);
},
serializer: (value: string) => {
try {
return JSON.parse(value);
} catch (error) {
// swallow error and return non-parsed value;
return value;
}
},
},
schema: t.any,
},
copy_to: {
fieldConfig: {
defaultValue: '',
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'
| 'point'
| 'wildcard'
/**
* 'other' is a special type that only exists inside of MappingsEditor as a placeholder
Expand Down Expand Up @@ -107,6 +108,7 @@ export type ParameterName =
| 'null_value_boolean'
| 'null_value_geo_point'
| 'null_value_ip'
| 'null_value_point'
| 'copy_to'
| 'dynamic'
| 'dynamic_toggle'
Expand Down

0 comments on commit 8d5fe94

Please sign in to comment.