Skip to content

Commit

Permalink
Merge pull request #6553 from Bargs/ingest/apiMappingChanges
Browse files Browse the repository at this point in the history
Update ingest API for ES 5.0 mapping changes
  • Loading branch information
Matt Bargar committed Mar 18, 2016
2 parents 9c9b962 + 017a611 commit a54f708
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
});
Expand All @@ -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();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,17 @@ 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}
}
};
}
else {
const fieldType = field.type === 'number' ? 'double' : field.type;
mapping = {
type: fieldType,
index: 'not_analyzed',
index: true,
doc_values: true
};
}
Expand Down
5 changes: 2 additions & 3 deletions src/plugins/kibana/server/routes/api/ingest/register_post.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
}
}
}
Expand Down
38 changes: 33 additions & 5 deletions test/unit/api/ingest/_post.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit a54f708

Please sign in to comment.