Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #12602 - Change TSVB Fields API to use fieldCaps API #12611

Merged
merged 4 commits into from
Jul 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@ describe('generateByTypeFilter()', () => {
describe('numeric', () => {
const fn = generateByTypeFilter('numeric');
[
'scaled_float',
'half_float',
'integer',
'float',
'long',
'double'
'number'
].forEach((type) => {
it(`should return true for ${type}`, () => expect(fn({ type })).to.equal(true));
});
Expand All @@ -34,12 +29,7 @@ describe('generateByTypeFilter()', () => {
describe('all', () => {
const fn = generateByTypeFilter('all');
[
'scaled_float',
'half_float',
'integer',
'float',
'long',
'double',
'number',
'string',
'text',
'keyword',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@ export default function byType(type) {
switch (type) {
case 'numeric':
return _.includes([
'scaled_float',
'half_float',
'integer',
'float',
'long',
'double'
'number'
], field.type);
case 'string':
return _.includes([
Expand Down
84 changes: 0 additions & 84 deletions src/core_plugins/metrics/server/lib/__tests__/get_fields.js

This file was deleted.

43 changes: 6 additions & 37 deletions src/core_plugins/metrics/server/lib/get_fields.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,9 @@
import _ from 'lodash';
import { uniq } from 'lodash';

export function getParams(req) {
export async function getFields(req) {
const { indexPatternsService } = req.pre;
const index = req.query.index || '*';
return {
index,
fields: ['*'],
ignoreUnavailable: false,
allowNoIndices: false,
includeDefaults: true
};
const resp = await indexPatternsService.getFieldsForWildcard({ pattern: index });
const fields = resp.filter(field => field.aggregatable);
return uniq(fields, field => field.name);
}

export function handleResponse(resp) {
return _.reduce(resp, (acc, index) => {
_.each(index.mappings, (type) => {
_.each(type, (field, fullName) => {
const name = _.last(fullName.split(/\./));
const enabled = _.get(field, `mapping.${name}.enabled`, true);
const fieldType = _.get(field, `mapping.${name}.type`);
if (enabled && fieldType) {
acc.push({
name: _.get(field, 'full_name', fullName),
type: fieldType
});
}
});
});
return _(acc).sortBy('name').uniq(row => row.name).value();
}, []);
}

function getFields(req) {
const { callWithRequest } = req.server.plugins.elasticsearch.getCluster('data');
const params = getParams(req);
return callWithRequest(req, 'indices.getFieldMapping', params).then(handleResponse);
}

export default getFields;

11 changes: 11 additions & 0 deletions src/core_plugins/metrics/server/lib/get_index_pattern_service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { IndexPatternsService } from '../../../../server/index_patterns/service';
export const getIndexPatternService = {
assign: 'indexPatternsService',
method(req, reply) {
const dataCluster = req.server.plugins.elasticsearch.getCluster('data');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When #13012 gets merged this can be simplified to req.getIndexPatternsService(), and could be moved to into the routes if desired.

const callDataCluster = (...args) => {
return dataCluster.callWithRequest(req, ...args);
};
reply(new IndexPatternsService(callDataCluster));
}
};
6 changes: 5 additions & 1 deletion src/core_plugins/metrics/server/routes/fields.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import getFields from '../lib/get_fields';
import { getFields } from '../lib/get_fields';
import { getIndexPatternService } from '../lib/get_index_pattern_service';
export default (server) => {

server.route({
config: {
pre: [getIndexPatternService]
},
path: '/api/metrics/fields',
method: 'GET',
handler: (req, reply) => {
Expand Down