mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
Add field_capabilities API
This adds a simple API for getting the searchable/aggregatable status of a list of fields in a given index, list of indices, or index pattern. In the future this will probably evolve into a full blown fields info API that we can use when removing the index pattern mapping cache. For now though it's built to provide the minimum info needed to fix https://github.com/elastic/kibana/issues/6769 Usage: The API exposes a single GET endpoint. ``` GET /api/kibana/{indices}/field_capabilities ``` `indices` can be a single index, a comma delimited list, or a wildcard pattern Example response: ``` { "fields": { "imsearchable": { "searchable": true, "aggregatable": false }, "imaggregatable": { "searchable": true, "aggregatable": true }, } } ```
This commit is contained in:
parent
2ebbd0ef66
commit
1af6b76bd4
4 changed files with 122 additions and 0 deletions
|
@ -3,6 +3,7 @@ import { registerDelete } from './register_delete';
|
|||
import { registerProcessors } from './register_processors';
|
||||
import { registerSimulate } from './register_simulate';
|
||||
import { registerData } from './register_data';
|
||||
import { registerFieldCapabilities } from './register_field_capabilities';
|
||||
|
||||
export default function (server) {
|
||||
registerPost(server);
|
||||
|
@ -10,4 +11,5 @@ export default function (server) {
|
|||
registerProcessors(server);
|
||||
registerSimulate(server);
|
||||
registerData(server);
|
||||
registerFieldCapabilities(server);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
import _ from 'lodash';
|
||||
import handleESError from '../../../lib/handle_es_error';
|
||||
|
||||
export function registerFieldCapabilities(server) {
|
||||
server.route({
|
||||
path: '/api/kibana/{indices}/field_capabilities',
|
||||
method: ['GET'],
|
||||
handler: function (req, reply) {
|
||||
const callWithRequest = server.plugins.elasticsearch.callWithRequest;
|
||||
const indices = req.params.indices || '';
|
||||
|
||||
return callWithRequest(req, 'fieldStats', {
|
||||
fields: '*',
|
||||
level: 'cluster',
|
||||
index: indices,
|
||||
allowNoIndices: false
|
||||
})
|
||||
.catch((error) => {
|
||||
reply(handleESError(error));
|
||||
})
|
||||
.then((res) => {
|
||||
const fields = _.get(res, 'indices._all.fields', {});
|
||||
const fieldsFilteredValues = _.mapValues(fields, (value) => {
|
||||
return _.pick(value, ['searchable', 'aggregatable']);
|
||||
});
|
||||
|
||||
reply({fields: fieldsFilteredValues});
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
87
test/unit/api/ingest/_field_capabilities.js
Normal file
87
test/unit/api/ingest/_field_capabilities.js
Normal file
|
@ -0,0 +1,87 @@
|
|||
define(function (require) {
|
||||
var Promise = require('bluebird');
|
||||
var _ = require('intern/dojo/node!lodash');
|
||||
var expect = require('intern/dojo/node!expect.js');
|
||||
|
||||
return function (bdd, scenarioManager, request) {
|
||||
bdd.describe('field_capabilities API', function postIngest() {
|
||||
|
||||
bdd.before(function () {
|
||||
return scenarioManager.client.create({
|
||||
index: 'foo-1',
|
||||
type: 'bar',
|
||||
id: '1',
|
||||
body: {
|
||||
foo: 'bar'
|
||||
}
|
||||
})
|
||||
.then(function () {
|
||||
return scenarioManager.client.create({
|
||||
index: 'foo-2',
|
||||
type: 'bar',
|
||||
id: '2',
|
||||
body: {
|
||||
baz: 'bar'
|
||||
}
|
||||
});
|
||||
})
|
||||
.then(function () {
|
||||
return scenarioManager.client.indices.refresh({
|
||||
index: ['foo-1', 'foo-2']
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
bdd.after(function () {
|
||||
return scenarioManager.reload('emptyKibana')
|
||||
.then(function () {
|
||||
scenarioManager.client.indices.delete({
|
||||
index: 'foo*'
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
bdd.it('should return searchable/aggregatable flags for fields in the indices specified', function () {
|
||||
return request.get('/kibana/foo-1/field_capabilities')
|
||||
.expect(200)
|
||||
.then(function (response) {
|
||||
var fields = response.body.fields;
|
||||
expect(fields.foo).to.eql({searchable: true, aggregatable: false});
|
||||
expect(fields['foo.keyword']).to.eql({searchable: true, aggregatable: true});
|
||||
expect(fields).to.not.have.property('baz');
|
||||
});
|
||||
});
|
||||
|
||||
bdd.it('should accept wildcards in the index name', function () {
|
||||
return request.get('/kibana/foo-*/field_capabilities')
|
||||
.expect(200)
|
||||
.then(function (response) {
|
||||
var fields = response.body.fields;
|
||||
expect(fields.foo).to.eql({searchable: true, aggregatable: false});
|
||||
expect(fields.baz).to.eql({searchable: true, aggregatable: false});
|
||||
});
|
||||
});
|
||||
|
||||
bdd.it('should accept comma delimited lists of indices', function () {
|
||||
return request.get('/kibana/foo-1,foo-2/field_capabilities')
|
||||
.expect(200)
|
||||
.then(function (response) {
|
||||
var fields = response.body.fields;
|
||||
expect(fields.foo).to.eql({searchable: true, aggregatable: false});
|
||||
expect(fields.baz).to.eql({searchable: true, aggregatable: false});
|
||||
});
|
||||
});
|
||||
|
||||
bdd.it('should return 404 if a pattern matches no indices', function () {
|
||||
return request.post('/kibana/doesnotexist-*/field_capabilities')
|
||||
.expect(404);
|
||||
});
|
||||
|
||||
bdd.it('should return 404 if a concrete index does not exist', function () {
|
||||
return request.post('/kibana/concrete/field_capabilities')
|
||||
.expect(404);
|
||||
});
|
||||
|
||||
});
|
||||
};
|
||||
});
|
|
@ -12,6 +12,7 @@ define(function (require) {
|
|||
var simulate = require('./_simulate');
|
||||
var processors = require('./_processors');
|
||||
var processorTypes = require('./processors/index');
|
||||
var fieldCapabilities = require('./_field_capabilities');
|
||||
|
||||
bdd.describe('ingest API', function () {
|
||||
var scenarioManager = new ScenarioManager(url.format(serverConfig.servers.elasticsearch));
|
||||
|
@ -31,5 +32,6 @@ define(function (require) {
|
|||
simulate(bdd, scenarioManager, request);
|
||||
processors(bdd, scenarioManager, request);
|
||||
processorTypes(bdd, scenarioManager, request);
|
||||
fieldCapabilities(bdd, scenarioManager, request);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue