mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
Update GET single pattern endpoint to use the new resource schema
This commit is contained in:
parent
636b444bf5
commit
bf45998057
3 changed files with 43 additions and 43 deletions
|
@ -15,7 +15,11 @@ module.exports = {
|
|||
Joi.object({
|
||||
name: Joi.string().required(),
|
||||
count: Joi.number().integer(),
|
||||
scripted: Joi.boolean()
|
||||
scripted: Joi.boolean(),
|
||||
doc_values: Joi.boolean(),
|
||||
analyzed: Joi.boolean(),
|
||||
indexed: Joi.boolean(),
|
||||
type: Joi.string()
|
||||
})
|
||||
),
|
||||
field_format_map: Joi.object()
|
||||
|
@ -47,7 +51,11 @@ module.exports = {
|
|||
Joi.object({
|
||||
name: Joi.string().required(),
|
||||
count: Joi.number().integer(),
|
||||
scripted: Joi.boolean()
|
||||
scripted: Joi.boolean(),
|
||||
doc_values: Joi.boolean(),
|
||||
analyzed: Joi.boolean(),
|
||||
indexed: Joi.boolean(),
|
||||
type: Joi.string()
|
||||
})
|
||||
),
|
||||
field_format_map: Joi.object()
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
const _ = require('lodash');
|
||||
const Promise = require('bluebird');
|
||||
const getMappings = require('../../../lib/get_mappings');
|
||||
const stitchPatternAndMappings = require('../../../lib/stitch_pattern_and_mappings');
|
||||
const removeDeprecatedFieldProps = require('../../../lib/remove_deprecated_field_props');
|
||||
const handleESError = require('../../../lib/handle_es_error');
|
||||
const createApiDocument = require('../../../lib/api_document_builders/create_api_document');
|
||||
const createRelationshipObject = require('../../../lib/api_document_builders/create_relationship_object');
|
||||
|
@ -89,7 +86,8 @@ module.exports = function registerGet(server) {
|
|||
method: 'GET',
|
||||
handler: function (req, reply) {
|
||||
const boundCallWithRequest = _.partial(server.plugins.elasticsearch.callWithRequest, req);
|
||||
let pattern = req.params.id;
|
||||
const shouldIncludeTemplate = req.query.include === 'template';
|
||||
const pattern = req.params.id;
|
||||
|
||||
const params = {
|
||||
index: '.kibana',
|
||||
|
@ -97,17 +95,34 @@ module.exports = function registerGet(server) {
|
|||
id: req.params.id
|
||||
};
|
||||
|
||||
Promise.join(
|
||||
boundCallWithRequest('get', params)
|
||||
.then((result) => {
|
||||
result._source.fields = JSON.parse(result._source.fields);
|
||||
return result._source;
|
||||
}),
|
||||
getMappings(pattern, boundCallWithRequest),
|
||||
stitchPatternAndMappings
|
||||
)
|
||||
.then(removeDeprecatedFieldProps)
|
||||
.then(convertToSnakeCase)
|
||||
boundCallWithRequest('get', params)
|
||||
.then((result) => {
|
||||
result._source.fields = JSON.parse(result._source.fields);
|
||||
|
||||
let relationshipsObject;
|
||||
if (result._source.template_id) {
|
||||
relationshipsObject = {
|
||||
template: createRelationshipObject('index_templates', result._source.template_id)
|
||||
};
|
||||
delete result._source.template_id;
|
||||
}
|
||||
|
||||
const snakeAttributes = convertToSnakeCase(result._source);
|
||||
return createResourceObject('index_patterns', result._id, snakeAttributes, relationshipsObject);
|
||||
})
|
||||
.then((patternResource) => {
|
||||
if (!shouldIncludeTemplate) {
|
||||
return createApiDocument(patternResource);
|
||||
}
|
||||
const templateId = _.get(patternResource, 'relationships.template.data.id');
|
||||
|
||||
return boundCallWithRequest('indices.getTemplate', {name: templateId})
|
||||
.then((template) => {
|
||||
return createApiDocument(patternResource, [
|
||||
createResourceObject('index_templates', templateId, template[templateId])
|
||||
]);
|
||||
});
|
||||
})
|
||||
.then(
|
||||
function (pattern) {
|
||||
reply(pattern);
|
||||
|
|
|
@ -87,7 +87,7 @@ define(function (require) {
|
|||
return request.get('/kibana/index_patterns/logstash-*')
|
||||
.expect(200)
|
||||
.then(function (res) {
|
||||
expect(res.body.title).to.be('logstash-*');
|
||||
expect(res.body.data.attributes.title).to.be('logstash-*');
|
||||
Joi.assert(res.body, indexPatternSchema.post);
|
||||
});
|
||||
});
|
||||
|
@ -96,31 +96,8 @@ define(function (require) {
|
|||
return request.get('/kibana/index_patterns/logstash-*')
|
||||
.expect(200)
|
||||
.then(function (res) {
|
||||
expectSnakeCase(res.body);
|
||||
});
|
||||
});
|
||||
|
||||
bdd.it('should return mappings info from the indices if there is no template', function () {
|
||||
var pattern = createTestData().indexPatternWithTemplate;
|
||||
pattern.fields = _.map(pattern.fields, function (field) {
|
||||
return _.omit(field, 'mapping');
|
||||
});
|
||||
|
||||
return request.del('/kibana/index_patterns/logstash-*').expect(200)
|
||||
.then(function () {
|
||||
return scenarioManager.load('makelogs');
|
||||
})
|
||||
.then(function () {
|
||||
return request.post('/kibana/index_patterns').send(pattern).expect(201);
|
||||
})
|
||||
.then(function () {
|
||||
return request.get('/kibana/index_patterns/logstash-*').expect(200);
|
||||
})
|
||||
.then(function (res) {
|
||||
expect(res.body.fields[0].mapping).to.be.an('object');
|
||||
})
|
||||
.finally(function () {
|
||||
scenarioManager.unload('makelogs');
|
||||
expectSnakeCase(res.body.data);
|
||||
expectSnakeCase(res.body.data.attributes);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue