mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
Add index_pattern key to ingest api payload schema to make room for the pipeline
This commit is contained in:
parent
e72cbc2ba2
commit
556b0cfbf7
4 changed files with 44 additions and 36 deletions
|
@ -0,0 +1,6 @@
|
|||
const Joi = require('joi');
|
||||
const ingestPatternSchema = require('./index_pattern_schema');
|
||||
|
||||
module.exports = Joi.object({
|
||||
index_pattern: ingestPatternSchema.required()
|
||||
});
|
|
@ -1,7 +1,7 @@
|
|||
const Boom = require('boom');
|
||||
const _ = require('lodash');
|
||||
const {templateToPattern, patternToTemplate} = require('../../../lib/convert_pattern_and_template_name');
|
||||
const indexPatternSchema = require('../../../lib/schemas/resources/index_pattern_schema');
|
||||
const ingestConfigSchema = require('../../../lib/schemas/resources/ingest_config_schema');
|
||||
const handleESError = require('../../../lib/handle_es_error');
|
||||
const { keysToCamelCaseShallow } = require('../../../lib/case_conversion');
|
||||
const createMappingsFromPatternFields = require('../../../lib/create_mappings_from_pattern_fields');
|
||||
|
@ -13,14 +13,14 @@ module.exports = function registerPost(server) {
|
|||
method: 'POST',
|
||||
config: {
|
||||
validate: {
|
||||
payload: indexPatternSchema
|
||||
payload: ingestConfigSchema
|
||||
}
|
||||
},
|
||||
handler: function (req, reply) {
|
||||
const callWithRequest = server.plugins.elasticsearch.callWithRequest;
|
||||
const requestDocument = _.cloneDeep(req.payload);
|
||||
const indexPatternId = requestDocument.id;
|
||||
const indexPattern = keysToCamelCaseShallow(requestDocument);
|
||||
const indexPattern = keysToCamelCaseShallow(requestDocument.index_pattern);
|
||||
const indexPatternId = indexPattern.id;
|
||||
delete indexPattern.id;
|
||||
|
||||
const mappings = createMappingsFromPatternFields(indexPattern.fields);
|
||||
|
|
|
@ -24,20 +24,20 @@ define(function (require) {
|
|||
.expect(400),
|
||||
|
||||
request.post('/kibana/ingest')
|
||||
.send(_.set(createTestData(), 'title', false))
|
||||
.send(_.set(createTestData(), 'index_pattern.title', false))
|
||||
.expect(400),
|
||||
|
||||
request.post('/kibana/ingest')
|
||||
.send(_.set(createTestData(), 'fields', {}))
|
||||
.send(_.set(createTestData(), 'index_pattern.fields', {}))
|
||||
.expect(400),
|
||||
|
||||
request.post('/kibana/ingest')
|
||||
.send(_.set(createTestData(), 'fields', []))
|
||||
.send(_.set(createTestData(), 'index_pattern.fields', []))
|
||||
.expect(400),
|
||||
|
||||
// Fields must have a name and type
|
||||
request.post('/kibana/ingest')
|
||||
.send(_.set(createTestData(), 'fields', [{count: 0}]))
|
||||
.send(_.set(createTestData(), 'index_pattern.fields', [{count: 0}]))
|
||||
.expect(400)
|
||||
]);
|
||||
});
|
||||
|
@ -144,22 +144,22 @@ define(function (require) {
|
|||
|
||||
bdd.it('should return 409 conflict when the pattern matches existing indices',
|
||||
function existingIndicesConflict() {
|
||||
var pattern = createTestData();
|
||||
pattern.id = pattern.title = '.kib*';
|
||||
var ingestConfig = createTestData();
|
||||
ingestConfig.index_pattern.id = ingestConfig.index_pattern.title = '.kib*';
|
||||
|
||||
return request.post('/kibana/ingest')
|
||||
.send(pattern)
|
||||
.send(ingestConfig)
|
||||
.expect(409);
|
||||
});
|
||||
|
||||
bdd.it('should enforce snake_case in the request body', function () {
|
||||
var pattern = createTestData();
|
||||
pattern = _.mapKeys(pattern, function (value, key) {
|
||||
var ingestConfig = createTestData();
|
||||
ingestConfig.index_pattern = _.mapKeys(ingestConfig.index_pattern, function (value, key) {
|
||||
return _.camelCase(key);
|
||||
});
|
||||
|
||||
return request.post('/kibana/ingest')
|
||||
.send(pattern)
|
||||
.send(ingestConfig)
|
||||
.expect(400);
|
||||
});
|
||||
|
||||
|
|
|
@ -1,26 +1,28 @@
|
|||
module.exports = function createTestData() {
|
||||
return {
|
||||
'id': 'logstash-*',
|
||||
'title': 'logstash-*',
|
||||
'time_field_name': '@timestamp',
|
||||
'fields': [
|
||||
{
|
||||
'name': 'ip',
|
||||
'type': 'ip'
|
||||
}, {
|
||||
'name': '@timestamp',
|
||||
'type': 'date'
|
||||
}, {
|
||||
'name': 'agent',
|
||||
'type': 'string'
|
||||
}, {
|
||||
'name': 'bytes',
|
||||
'type': 'number'
|
||||
},
|
||||
{
|
||||
'name': 'geo.coordinates',
|
||||
'type': 'geo_point'
|
||||
}
|
||||
]
|
||||
'index_pattern': {
|
||||
'id': 'logstash-*',
|
||||
'title': 'logstash-*',
|
||||
'time_field_name': '@timestamp',
|
||||
'fields': [
|
||||
{
|
||||
'name': 'ip',
|
||||
'type': 'ip'
|
||||
}, {
|
||||
'name': '@timestamp',
|
||||
'type': 'date'
|
||||
}, {
|
||||
'name': 'agent',
|
||||
'type': 'string'
|
||||
}, {
|
||||
'name': 'bytes',
|
||||
'type': 'number'
|
||||
},
|
||||
{
|
||||
'name': 'geo.coordinates',
|
||||
'type': 'geo_point'
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue