Update ingest API for ES 5.0 mapping changes

This commit is contained in:
Matthew Bargar 2016-03-16 18:01:10 -04:00
parent 45e0b9ccf2
commit 017a6117f7
4 changed files with 43 additions and 17 deletions

View file

@ -39,21 +39,21 @@ describe('createMappingsFromPatternFields', function () {
let mappings = createMappingsFromPatternFields(testFields);
_.forEach(mappings, function (mapping) {
if (mapping.type !== 'string') {
if (mapping.type !== 'text') {
expect(_.isEqual(mapping, {
type: mapping.type,
index: 'not_analyzed',
index: true,
doc_values: true
})).to.be.ok();
}
});
});
it('should give strings a multi-field mapping', function () {
it('should give strings a multi-field mapping with a "text" base type', function () {
let mappings = createMappingsFromPatternFields(testFields);
_.forEach(mappings, function (mapping) {
if (mapping.type === 'string') {
if (mapping.type === 'text') {
expect(mapping).to.have.property('fields');
}
});
@ -68,7 +68,7 @@ describe('createMappingsFromPatternFields', function () {
expect(mappings.geo.properties).to.have.property('coordinates');
expect(_.isEqual(mappings.geo.properties.coordinates, {
type: 'geo_point',
index: 'not_analyzed',
index: true,
doc_values: true
})).to.be.ok();
});

View file

@ -13,10 +13,9 @@ module.exports = function createMappingsFromPatternFields(fields) {
if (field.type === 'string') {
mapping = {
type: 'string',
index: 'analyzed',
type: 'text',
fields: {
raw: {type: 'string', index: 'not_analyzed', doc_values: true, ignore_above: 256}
raw: {type: 'keyword', ignore_above: 256}
}
};
}
@ -24,7 +23,7 @@ module.exports = function createMappingsFromPatternFields(fields) {
const fieldType = field.type === 'number' ? 'double' : field.type;
mapping = {
type: fieldType,
index: 'not_analyzed',
index: true,
doc_values: true
};
}

View file

@ -58,10 +58,9 @@ module.exports = function registerPost(server) {
match: '*',
match_mapping_type: 'string',
mapping: {
type: 'string',
index: 'analyzed',
type: 'text',
fields: {
raw: {type: 'string', index: 'not_analyzed', doc_values: true, ignore_above: 256}
raw: {type: 'keyword', ignore_above: 256}
}
}
}

View file

@ -12,7 +12,12 @@ define(function (require) {
});
bdd.afterEach(function () {
return request.del('/kibana/ingest/logstash-*');
return request.del('/kibana/ingest/logstash-*')
.then(function () {
return scenarioManager.client.indices.delete({
index: 'logstash-*'
});
});
});
bdd.it('should return 400 for an invalid payload', function invalidPayload() {
@ -57,6 +62,29 @@ define(function (require) {
});
});
bdd.it('should successfully create new indices based on the template', function newIndices() {
return request.post('/kibana/ingest')
.send(createTestData())
.expect(204)
.then(function () {
return scenarioManager.client.create({
index: 'logstash-1',
type: 'foo',
id: '1',
body: {
ip: '192.168.1.1',
'@timestamp': '2015-09-20T10:28:22.684Z',
agent: 'Jack',
bytes: 9001,
geo: {coordinates: {lat: 43.07260861, lon: -92.61077833}}
}
})
.then(function (response) {
expect(response.created).to.be.ok();
});
});
});
bdd.it('should provide defaults for field properties', function createTemplate() {
return request.post('/kibana/ingest')
.send(createTestData())
@ -92,15 +120,15 @@ define(function (require) {
.then(function (template) {
var mappings = template['kibana-logstash-*'].mappings._default_.properties;
expect(mappings).to.be.ok();
expect(_.isEqual(mappings.ip, {index: 'not_analyzed', type: 'ip', doc_values: true})).to.be.ok();
expect(_.isEqual(mappings['@timestamp'], {index: 'not_analyzed', type: 'date', doc_values: true})).to.be.ok();
expect(_.isEqual(mappings.bytes, {index: 'not_analyzed', type: 'double', doc_values: true})).to.be.ok();
expect(_.isEqual(mappings.ip, {index: true, type: 'ip', doc_values: true})).to.be.ok();
expect(_.isEqual(mappings['@timestamp'], {index: true, type: 'date', doc_values: true})).to.be.ok();
expect(_.isEqual(mappings.bytes, {index: true, type: 'double', doc_values: true})).to.be.ok();
// object fields are mapped as such, with individual mappings for each of their properties
expect(_.isEqual(mappings.geo, {
properties: {
coordinates: {
index: 'not_analyzed',
index: true,
type: 'geo_point',
doc_values: true
}