mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
use savedObjectsClient to get index-patterns (#25630)
This commit is contained in:
parent
8d61ddf7f8
commit
30ebf9c2dc
4 changed files with 13 additions and 48 deletions
|
@ -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` }));
|
||||
};
|
||||
|
|
|
@ -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');
|
||||
});
|
||||
}
|
|
@ -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));
|
||||
},
|
||||
});
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue