Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[utils] add util for converting between es and kibana types #11967

Merged
merged 12 commits into from
May 24, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import angular from 'angular';
import rison from 'rison-node';
import { savedObjectManagementRegistry } from 'plugins/kibana/management/saved_object_registry';
import objectViewHTML from 'plugins/kibana/management/sections/objects/_view.html';
import { IndexPatternsCastMappingTypeProvider } from 'ui/index_patterns/_cast_mapping_type';
import uiRoutes from 'ui/routes';
import { uiModules } from 'ui/modules';
import { castEsToKbnFieldTypeName } from '../../../../../../utils';

uiRoutes
.when('/management/kibana/objects/:service/:id', {
Expand All @@ -16,9 +16,8 @@ uiModules.get('apps/management')
.directive('kbnManagementObjectsView', function (kbnIndex, Notifier, confirmModal) {
return {
restrict: 'E',
controller: function ($scope, $injector, $routeParams, $location, $window, $rootScope, esAdmin, Private) {
controller: function ($scope, $injector, $routeParams, $location, $window, $rootScope, esAdmin) {
const notify = new Notifier({ location: 'SavedObject view' });
const castMappingType = Private(IndexPatternsCastMappingTypeProvider);
const serviceObj = savedObjectManagementRegistry.get($routeParams.service);
const service = $injector.get(serviceObj.service);

Expand Down Expand Up @@ -81,7 +80,7 @@ uiModules.get('apps/management')
fields.push({
name: name,
type: (function () {
switch (castMappingType(esType)) {
switch (castEsToKbnFieldTypeName(esType)) {
case 'string': return 'text';
case 'number': return 'number';
case 'boolean': return 'boolean';
Expand Down
34 changes: 18 additions & 16 deletions src/fixtures/logstash_fields.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,43 @@
import { castEsToKbnFieldTypeName } from '../utils';

function stubbedLogstashFields() {
return [
// |indexed
// | |analyzed
// | | |aggregatable
// | | | |searchable
// name type | | | | |metadata
['bytes', 'number', true, true, true, true, { count: 10, docValues: true } ],
['bytes', 'long', true, true, true, true, { count: 10, docValues: true } ],
['ssl', 'boolean', true, true, true, true, { count: 20 } ],
['@timestamp', 'date', true, true, true, true, { count: 30 } ],
['time', 'date', true, true, true, true, { count: 30 } ],
['@tags', 'string', true, true, true, true ],
['@tags', 'keyword', true, true, true, true ],
['utc_time', 'date', true, true, true, true ],
['phpmemory', 'number', true, true, true, true ],
['phpmemory', 'integer', true, true, true, true ],
['ip', 'ip', true, true, true, true ],
['request_body', 'attachment', true, true, true, true ],
['point', 'geo_point', true, true, true, true ],
['area', 'geo_shape', true, true, true, true ],
['hashed', 'murmur3', true, true, false, true ],
['geo.coordinates', 'geo_point', true, true, true, true ],
['extension', 'string', true, true, true, true ],
['machine.os', 'string', true, true, true, true ],
['machine.os.raw', 'string', true, false, true, true, { docValues: true } ],
['geo.src', 'string', true, true, true, true ],
['_id', 'string', false, false, true, true ],
['_type', 'string', false, false, true, true ],
['_source', 'string', false, false, true, true ],
['non-filterable', 'string', false, false, true, false],
['non-sortable', 'string', false, false, false, false],
['extension', 'keyword', true, true, true, true ],
['machine.os', 'text', true, true, true, true ],
['machine.os.raw', 'keyword', true, false, true, true, { docValues: true } ],
['geo.src', 'keyword', true, true, true, true ],
['_id', 'keyword', false, false, true, true ],
['_type', 'keyword', false, false, true, true ],
['_source', 'keyword', false, false, true, true ],
['non-filterable', 'text', false, false, true, false],
['non-sortable', 'text', false, false, false, false],
['custom_user_field', 'conflict', false, false, true, true ],
['script string', 'string', false, false, true, false, { script: '\'i am a string\'' } ],
['script number', 'number', false, false, true, false, { script: '1234' } ],
['script string', 'text', false, false, true, false, { script: '\'i am a string\'' } ],
['script number', 'long', false, false, true, false, { script: '1234' } ],
['script date', 'date', false, false, true, false, { script: '1234', lang: 'painless' } ],
['script murmur3', 'murmur3', false, false, true, false, { script: '1234' } ],
].map(function (row) {
const [
name,
type,
esType,
indexed,
analyzed,
aggregatable,
Expand All @@ -53,7 +55,7 @@ function stubbedLogstashFields() {

return {
name,
type,
type: castEsToKbnFieldTypeName(esType),
doc_values: docValues,
indexed,
analyzed,
Expand Down
18 changes: 8 additions & 10 deletions src/fixtures/stubbed_logstash_index_pattern.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
import _ from 'lodash';
import TestUtilsStubIndexPatternProvider from 'test_utils/stub_index_pattern';
import { IndexPatternsFieldTypesProvider } from 'ui/index_patterns/_field_types';
import FixturesLogstashFieldsProvider from 'fixtures/logstash_fields';
import { castEsToKbnFieldType } from '../utils';

export default function stubbedLogstashIndexPatternService(Private) {
const StubIndexPattern = Private(TestUtilsStubIndexPatternProvider);
const fieldTypes = Private(IndexPatternsFieldTypesProvider);
const mockLogstashFields = Private(FixturesLogstashFieldsProvider);


const fields = mockLogstashFields.map(function (field) {
field.displayName = field.name;
const type = fieldTypes.byName[field.type];
if (!type) throw new TypeError('unknown type ' + field.type);
if (!_.has(field, 'sortable')) field.sortable = type.sortable;
if (!_.has(field, 'filterable')) field.filterable = type.filterable;
return field;
const kbnType = castEsToKbnFieldType(field.type);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is always returning the unknown field type because field.type already has the kibana type name.

return {
...field,
sortable: ('sortable' in field) ? !!field.sortable : kbnType.sortable,
filterable: ('filterable' in field) ? !!field.filterable : kbnType.filterable,
displayName: field.name,
};
});

const indexPattern = new StubIndexPattern('logstash-*', 'time', fields);
Expand Down
4 changes: 2 additions & 2 deletions src/ui/public/field_editor/field_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import { RegistryFieldFormatsProvider } from 'ui/registry/field_formats';
import { IndexPatternsFieldProvider } from 'ui/index_patterns/_field';
import { uiModules } from 'ui/modules';
import fieldEditorTemplate from 'ui/field_editor/field_editor.html';
import { IndexPatternsCastMappingTypeProvider } from 'ui/index_patterns/_cast_mapping_type';
import { documentationLinks } from '../documentation_links/documentation_links';
import './field_editor.less';
import { GetEnabledScriptingLanguagesProvider, getSupportedScriptingLanguages } from '../scripting_languages';
import { getEsTypes } from '../../../utils';

uiModules
.get('kibana', ['colorpicker.module'])
Expand All @@ -21,7 +21,7 @@ uiModules
const fieldTypesByLang = {
painless: ['number', 'string', 'date', 'boolean'],
expression: ['number'],
default: _.keys(Private(IndexPatternsCastMappingTypeProvider).types.byType)
default: getEsTypes()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a list of Kibana types, not ES types.

};

return {
Expand Down
68 changes: 0 additions & 68 deletions src/ui/public/index_patterns/__tests__/_cast_mapping_type.js

This file was deleted.

1 change: 0 additions & 1 deletion src/ui/public/index_patterns/__tests__/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import './_index_pattern';
import './_cast_mapping_type';
import './_map_field';
import './_pattern_to_wildcard';
import './_get_computed_fields';
Expand Down
45 changes: 0 additions & 45 deletions src/ui/public/index_patterns/_cast_mapping_type.js

This file was deleted.

7 changes: 3 additions & 4 deletions src/ui/public/index_patterns/_field.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { ObjDefine } from 'ui/utils/obj_define';
import { IndexPatternsFieldFormatProvider } from 'ui/index_patterns/_field_format/field_format';
import { IndexPatternsFieldTypesProvider } from 'ui/index_patterns/_field_types';
import { RegistryFieldFormatsProvider } from 'ui/registry/field_formats';
import { getKbnFieldType } from '../../../utils';

export function IndexPatternsFieldProvider(Private, shortDotsFilter, $rootScope, Notifier) {
const notify = new Notifier({ location: 'IndexPattern Field' });
const FieldFormat = Private(IndexPatternsFieldFormatProvider);
const fieldTypes = Private(IndexPatternsFieldTypesProvider);
const fieldFormats = Private(RegistryFieldFormatsProvider);

function Field(indexPattern, spec) {
Expand All @@ -23,7 +22,7 @@ export function IndexPatternsFieldProvider(Private, shortDotsFilter, $rootScope,
}

// find the type for this field, fallback to unknown type
let type = fieldTypes.byName[spec.type];
let type = getKbnFieldType(spec.type);
if (spec.type && !type) {
notify.error(
'Unknown field type "' + spec.type + '"' +
Expand All @@ -32,7 +31,7 @@ export function IndexPatternsFieldProvider(Private, shortDotsFilter, $rootScope,
);
}

if (!type) type = fieldTypes.byName.unknown;
if (!type) type = getKbnFieldType('unknown');

let format = spec.format;
if (!format || !(format instanceof FieldFormat)) {
Expand Down
24 changes: 0 additions & 24 deletions src/ui/public/index_patterns/_field_types.js

This file was deleted.

7 changes: 3 additions & 4 deletions src/ui/public/index_patterns/_map_field.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import _ from 'lodash';
import { IndexPatternsCastMappingTypeProvider } from 'ui/index_patterns/_cast_mapping_type';

export function IndexPatternsMapFieldProvider(Private, config) {
const castMappingType = Private(IndexPatternsCastMappingTypeProvider);
import { castEsToKbnFieldTypeName } from '../../../utils';

export function IndexPatternsMapFieldProvider(Private, config) {
/**
* Accepts a field object and its name, and tries to give it a mapping
* @param {Object} field - the field mapping returned by elasticsearch
Expand Down Expand Up @@ -41,7 +40,7 @@ export function IndexPatternsMapFieldProvider(Private, config) {

mapping.analyzed = mapping.index === 'analyzed' || mapping.type === 'text';

mapping.type = castMappingType(mapping.type);
mapping.type = castEsToKbnFieldTypeName(mapping.type);

if (mappingOverrides[name]) {
_.merge(mapping, mappingOverrides[name]);
Expand Down
Loading