-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
--------- **Commit 1:** 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 #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 }, } } ``` * Original sha: 1af6b76 * Authored by Matthew Bargar <[email protected]> on 2016-09-21T18:38:34Z **Commit 2:** Filter non-aggregatable fields from vis editor UI Using the field_capabilities API added in the previous commit, this commit enhances the client side index pattern object with information about the searchable and aggregatable status of each field in the index pattern. We then use this information to filter out non-aggregatable fields from the vis editor so that users won't accidentally select them and get nasty errors. An example of a non-aggregatable field would be a `text` field without fielddata enabled (which is the default). I also added the searchable and aggregatable flags to the index pattern page so users can see the status of their fields. I removed the `indexed` column because it was mostly redundant with `searchable` and I needed the horizontal space. The addition of the searchable and aggregatable properties for index pattern fields would require users to manually refresh their field list when upgrading to 5.0. This commit also adds a check for those properties and if they're missing it automatically refreshes the field list for the user in a seamless manner. * Original sha: 4a906f3 * Authored by Matthew Bargar <[email protected]> on 2016-09-21T19:18:10Z
- Loading branch information
1 parent
64ef508
commit 1c53b0d
Showing
11 changed files
with
205 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/core_plugins/kibana/server/routes/api/ingest/register_field_capabilities.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}); | ||
}); | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/ui/public/index_patterns/_enhance_fields_with_capabilities.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import chrome from 'ui/chrome'; | ||
import _ from 'lodash'; | ||
|
||
export default function ($http) { | ||
|
||
return function (fields, indices) { | ||
return $http.get(chrome.addBasePath(`/api/kibana/${indices}/field_capabilities`)) | ||
.then((res) => { | ||
const stats = _.get(res, 'data.fields', {}); | ||
|
||
return _.map(fields, (field) => { | ||
return _.assign(field, stats[field.name]); | ||
}); | ||
}); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); | ||
|
||
}); | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters