-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix master conflicts. Merge it like its #1999
- Loading branch information
Showing
9 changed files
with
218 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
define(function (require) { | ||
return function MapFieldFn(Private, config) { | ||
var _ = require('lodash'); | ||
var castMappingType = Private(require('components/index_patterns/_cast_mapping_type')); | ||
|
||
/** | ||
* Accepts a field object and its name, and tries to give it a mapping | ||
* @param {Object} field - the field mapping returned by elasticsearch | ||
* @param {String} type - name of the field | ||
* @return {Object} - the resulting field after overrides and tweaking | ||
*/ | ||
return function mapField(field, name) { | ||
var keys = Object.keys(field.mapping); | ||
if (keys.length === 0 || (name[0] === '_') && !_.contains(config.get('metaFields'), name)) return; | ||
|
||
var mapping = _.cloneDeep(field.mapping[keys.shift()]); | ||
mapping.type = castMappingType(mapping.type); | ||
|
||
// Override the mapping, even if elasticsearch says otherwise | ||
var mappingOverrides = { | ||
_id: { | ||
indexed: true | ||
}, | ||
_timestamp: { | ||
indexed: true, | ||
type: 'date' | ||
} | ||
}; | ||
|
||
if (!mapping.index || mapping.index === 'no') { | ||
// elasticsearch responds with false sometimes and 'no' others | ||
mapping.indexed = false; | ||
} else { | ||
mapping.indexed = true; | ||
} | ||
|
||
mapping.analyzed = mapping.index === 'analyzed' ? true : false; | ||
|
||
if (mappingOverrides[name]) { | ||
_.merge(mapping, mappingOverrides[name]); | ||
} | ||
|
||
return mapping; | ||
}; | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
test/unit/specs/components/index_pattern/_cast_mapping_type.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
define(function (require) { | ||
return ['type normalizer (castMappingType)', function () { | ||
var _ = require('lodash'); | ||
|
||
var fn; | ||
var fields; | ||
beforeEach(module('kibana')); | ||
beforeEach(inject(function (Private, $injector) { | ||
fn = Private(require('components/index_patterns/_cast_mapping_type')); | ||
})); | ||
|
||
it('should be a function', function () { | ||
expect(fn).to.be.a(Function); | ||
}); | ||
|
||
it('should cast numeric types to "number"', function () { | ||
var types = [ | ||
'float', | ||
'double', | ||
'integer', | ||
'long', | ||
'short', | ||
'byte', | ||
'token_count' | ||
]; | ||
|
||
_.each(types, function (type) { | ||
expect(fn(type)).to.be('number'); | ||
}); | ||
}); | ||
|
||
it('should treat non-numeric known types as what they are', function () { | ||
var types = [ | ||
'date', | ||
'boolean', | ||
'ip', | ||
'attachment', | ||
'geo_point', | ||
'geo_shape', | ||
'string' | ||
]; | ||
|
||
_.each(types, function (type) { | ||
expect(fn(type)).to.be(type); | ||
}); | ||
}); | ||
|
||
it('should treat everything else as a string', function () { | ||
expect(fn('fooTypeIsNotReal')).to.be('string'); | ||
}); | ||
|
||
}]; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
define(function (require) { | ||
return ['field mapping normalizer (mapField)', function () { | ||
var _ = require('lodash'); | ||
|
||
var fn; | ||
var fields; | ||
beforeEach(module('kibana')); | ||
beforeEach(inject(function (Private, $injector, config) { | ||
config.set('metaFields', ['_id', '_timestamp']); | ||
fn = Private(require('components/index_patterns/_map_field')); | ||
fields = require('fixtures/field_mapping').test.mappings.testType; | ||
})); | ||
|
||
it('should be a function', function () { | ||
expect(fn).to.be.a(Function); | ||
}); | ||
|
||
it('should return a modified copy of the object, not modify the original', function () { | ||
var pristine = _.cloneDeep(fields['foo.bar']); | ||
var mapped = fn(fields['foo.bar'], 'foo.bar'); | ||
|
||
expect(fields['foo.bar']).to.not.eql(mapped); | ||
expect(fields['foo.bar']).to.eql(pristine); | ||
}); | ||
|
||
it('should always consider _id to be indexed', function () { | ||
var mapped = fn(fields['_id'], '_id'); | ||
expect(mapped.indexed).to.be(true); | ||
}); | ||
|
||
it('should always consider _timestamp to be an indexed date', function () { | ||
var mapped = fn(fields['_timestamp'], '_timestamp'); | ||
expect(mapped.indexed).to.be(true); | ||
expect(mapped.type).to.be('date'); | ||
}); | ||
|
||
it('should treat falsy and no as false for index', function () { | ||
var mapped = fn(fields['index_no_field'], 'index_no_field'); | ||
expect(mapped.indexed).to.be(false); | ||
|
||
fields['index_no_field'].index = false; | ||
mapped = fn(fields['index_no_field'], 'index_no_field'); | ||
expect(mapped.indexed).to.be(false); | ||
}); | ||
|
||
it('should treat other values for index as true', function () { | ||
var mapped = fn(fields['not_analyzed_field'], 'not_analyzed_field'); | ||
expect(mapped.indexed).to.be(true); | ||
}); | ||
|
||
}]; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
define(function (require) { | ||
describe('Index Patterns', function () { | ||
run(require('specs/components/index_pattern/_cast_mapping_type')); | ||
run(require('specs/components/index_pattern/_map_field')); | ||
run(require('specs/components/index_pattern/_pattern_to_wildcard')); | ||
function run(mod) { describe(mod[0], mod[1]); } | ||
}); | ||
}); |