Skip to content

Commit

Permalink
fix master conflicts. Merge it like its #1999
Browse files Browse the repository at this point in the history
  • Loading branch information
Rashid Khan committed Nov 21, 2014
2 parents 4d52fb5 + 427c34d commit 036d850
Show file tree
Hide file tree
Showing 9 changed files with 218 additions and 34 deletions.
2 changes: 2 additions & 0 deletions src/kibana/components/courier/data_source/_abstract.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ define(function (require) {
'match_all': {}
};
}
flatState.body.fields = ['*', '_source'];


/**
* Create a filter that can be reversed for filters with negate set
Expand Down
46 changes: 46 additions & 0 deletions src/kibana/components/index_patterns/_map_field.js
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;
};
};
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ define(function (require) {
var _ = require('lodash');
var MappingConflict = require('errors').MappingConflict;
var castMappingType = Private(require('components/index_patterns/_cast_mapping_type'));
var mapField = Private(require('components/index_patterns/_map_field'));


/**
* Convert the ES response into the simple map for fields to
Expand All @@ -22,20 +24,7 @@ define(function (require) {
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);

if (name === '_id') {
// _id is allways indexed
mapping.indexed = true;
} else 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;
var mapping = mapField(field, name);

if (fields[name]) {
if (fields[name].type !== mapping.type
Expand Down
21 changes: 8 additions & 13 deletions src/kibana/plugins/discover/controllers/discover.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,6 @@ define(function (require) {

var metaFields = config.get('metaFields');

$scope.intervalOptions = [
'auto',
'second',
'minute',
'hour',
'day',
'week',
'month',
'year'
];

var $state = $scope.state = new AppState(stateDefaults);

if (!_.contains(indexPatternList, $state.index)) {
Expand Down Expand Up @@ -343,13 +332,19 @@ define(function (require) {
var indexPattern = $scope.searchSource.get('index');
hit._source = indexPattern.flattenSearchResponse(hit._source);

hit._formatted = _.mapValues(hit._source, function (value, name) {
var formatValues = function (value, name) {
// add up the counts for each field name
if (counts[name]) counts[name] = counts[name] + 1;
else counts[name] = 1;

return ($scope.formatsByName[name] || defaultFormat).convert(value);
});
};

var formattedSource = _.mapValues(hit._source, formatValues);
var formattedHits = _.mapValues(hit.fields, formatValues);

hit._formatted = _.merge(formattedSource, formattedHits);
hit._formatted._source = angular.toJson(hit._source);
});

// ensure that the meta fields always have a "row count" equal to the number of rows
Expand Down
38 changes: 37 additions & 1 deletion test/unit/fixtures/field_mapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,43 @@ define(function (require) {
full_name: 'foo.bar',
mapping: {
bar: {
type: 'string'
type: 'string',
}
}
},
'not_analyzed_field': {
full_name: 'not_analyzed_field',
mapping: {
bar: {
type: 'string',
index: 'not_analyzed'
}
}
},
'index_no_field': {
full_name: 'index_no_field',
mapping: {
bar: {
type: 'string',
index: 'no'
}
}
},
_id: {
full_name: '_id',
mapping: {
_id: {
store: false,
index: 'no',
}
}
},
_timestamp: {
full_name: '_timestamp',
mapping: {
_timestamp: {
store: true,
index: 'no',
}
}
}
Expand Down
53 changes: 53 additions & 0 deletions test/unit/specs/components/index_pattern/_cast_mapping_type.js
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');
});

}];
});
52 changes: 52 additions & 0 deletions test/unit/specs/components/index_pattern/_map_field.js
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);
});

}];
});
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
define(function (require) {
return ['Index pattern to wildcard', function () {

var fn = require('components/index_patterns/_pattern_to_wildcard')();
var fn = require('components/index_patterns/_pattern_to_wildcard')();

describe('patternToWildard function', function () {

it('should be a function', function () {
expect(fn).to.be.a(Function);
Expand All @@ -25,10 +25,13 @@ define(function (require) {
expect(fn('[f[oo-]YYYY')).to.equal('f[oo-*');
});

// Not sure if this behavior is useful, but this is how the code works
it('should add ] to the string when outside the pattern', function () {
expect(fn('[foo-]]YYYY')).to.equal('foo-]*');
});

it('should ignore ] when outside an escape', function () {
expect(fn('[f]oo-]YYYY')).to.equal('f*');
});

});

});
}];
});
8 changes: 8 additions & 0 deletions test/unit/specs/components/index_pattern/index.js
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]); }
});
});

0 comments on commit 036d850

Please sign in to comment.