use savedObjectsClient to get index-patterns (#25630)

This commit is contained in:
Nathan Reese 2018-11-15 16:02:57 -07:00 committed by GitHub
parent 8d61ddf7f8
commit 30ebf9c2dc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 48 deletions

View file

@ -26,8 +26,18 @@ export const getFields = (index = '_all') => {
};
export const getIndices = () => {
return fetch
.get(`${apiPath}/es_indices`)
.then(({ data: indices }) => indices)
const savedObjectsClient = chrome.getSavedObjectsClient();
return savedObjectsClient
.find({
type: 'index-pattern',
fields: ['title'],
search_fields: ['title'],
perPage: 1000,
})
.then(resp => {
return resp.savedObjects.map(savedObject => {
return savedObject.attributes.title;
});
})
.catch(err => notify.error(err, { title: `Couldn't fetch Elasticsearch indices` }));
};

View file

@ -1,20 +0,0 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { map } from 'lodash';
export function getESIndices(kbnIndex, elasticsearchClient) {
const config = {
index: kbnIndex,
_source: 'index-pattern.title',
q: 'type:"index-pattern"',
size: 100,
};
return elasticsearchClient('search', config).then(resp => {
return map(resp.hits.hits, '_source["index-pattern"].title');
});
}

View file

@ -1,23 +0,0 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { partial } from 'lodash';
import { getESIndices } from './get_es_indices';
// TODO: Error handling, note: esErrors
// TODO: Allow filtering by pattern name
export function esIndices(server) {
const kbnIndex = server.config().get('kibana.index');
const { callWithRequest } = server.plugins.elasticsearch.getCluster('data');
server.route({
method: 'GET',
path: '/api/canvas/es_indices',
handler: function(request) {
return getESIndices(kbnIndex, partial(callWithRequest, request));
},
});
}

View file

@ -8,7 +8,6 @@ import { workpad } from './workpad';
import { socketApi } from './socket';
import { translate } from './translate';
import { esFields } from './es_fields';
import { esIndices } from './es_indices';
import { plugins } from './plugins';
export function routes(server) {
@ -16,6 +15,5 @@ export function routes(server) {
socketApi(server);
translate(server);
esFields(server);
esIndices(server);
plugins(server);
}