Better defaults for scripted fields and prevent scripted fields from getting in the index template

This commit is contained in:
Matthew Bargar 2016-01-04 17:12:58 -05:00
parent 895164607b
commit d4e85bc7da
2 changed files with 44 additions and 8 deletions

View file

@ -3,7 +3,6 @@ const _ = require('lodash');
const {templateToPattern, patternToTemplate} = require('../../../lib/convert_pattern_and_template_name');
const indexPatternSchema = require('../../../lib/schemas/resources/index_pattern_schema');
const handleESError = require('../../../lib/handle_es_error');
const addMappingInfoToPatternFields = require('../../../lib/add_mapping_info_to_pattern_fields');
const { convertToCamelCase } = require('../../../lib/case_conversion');
const createMappingFromPatternField = require('../../../lib/create_mapping_from_pattern_field');
const castMappingType = require('../../../lib/cast_mapping_type');
@ -24,16 +23,27 @@ module.exports = function registerPost(server) {
const indexPattern = convertToCamelCase(requestDocument.data.attributes);
_.forEach(indexPattern.fields, function (field) {
_.defaults(field, {
indexed: true,
analyzed: false,
doc_values: true,
scripted: false,
count: 0
});
if (field.scripted) {
_.defaults(field, {
indexed: false,
analyzed: false,
doc_values: false,
count: 0
});
}
else {
_.defaults(field, {
indexed: true,
analyzed: false,
doc_values: true,
scripted: false,
count: 0
});
}
});
const mappings = _(indexPattern.fields)
.reject('scripted')
.indexBy('name')
.mapValues(createMappingFromPatternField)
.value();

View file

@ -97,6 +97,32 @@ define(function (require) {
});
});
bdd.it('scripted fields should not get added to the template', function createTemplate() {
var testData = createTestData().indexPattern;
testData.data.attributes.fields.push({
'name': 'Double Bytes',
'type': 'number',
'scripted': true,
'script': 'doc[\'bytes\'].value * 2',
'lang': 'expression',
'indexed': false,
'analyzed': false,
'doc_values': false
});
return request.post('/kibana/index_patterns')
.send(testData)
.expect(201)
.then(function () {
return scenarioManager.client.indices.getTemplate({name: 'kibana-logstash-*'})
.then(function (template) {
var mappings = template['kibana-logstash-*'].mappings._default_.properties;
expect(mappings).to.be.ok();
expect(mappings).to.not.have.property('Double Bytes');
});
});
});
bdd.it('should return 409 conflict when a pattern with the given ID already exists', function patternConflict() {
return request.post('/kibana/index_patterns')
.send(createTestData().indexPattern)