Skip to content

Commit

Permalink
Fields dropdowns are not populated if one of the indices is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
DianaDerevyankina committed Sep 14, 2020
1 parent 2e34eb2 commit 14cd01c
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ export class IndexPatternsFetcher {
async getFieldsForWildcard(options: {
pattern: string | string[];
metaFields?: string[];
fieldCapsOptions?: { allowNoIndices: boolean };
}): Promise<FieldDescriptor[]> {
const { pattern, metaFields } = options;
return await getFieldCapabilities(this._callDataCluster, pattern, metaFields);
const { pattern, metaFields, fieldCapsOptions } = options;
return await getFieldCapabilities(this._callDataCluster, pattern, metaFields, fieldCapsOptions);
}

/**
Expand Down
9 changes: 7 additions & 2 deletions src/plugins/data/server/index_patterns/fetcher/lib/es_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,20 @@ export async function callIndexAliasApi(
*
* @param {Function} callCluster bound function for accessing an es client
* @param {Array<String>|String} indices
* @param {Object} fieldCapsOptions
* @return {Promise<FieldCapsResponse>}
*/
export async function callFieldCapsApi(callCluster: LegacyAPICaller, indices: string[] | string) {
export async function callFieldCapsApi(
callCluster: LegacyAPICaller,
indices: string[] | string,
fieldCapsOptions: { allowNoIndices: boolean } = { allowNoIndices: false }
) {
try {
return (await callCluster('fieldCaps', {
index: indices,
fields: '*',
ignoreUnavailable: true,
allowNoIndices: false,
...fieldCapsOptions,
})) as FieldCapsResponse;
} catch (error) {
throw convertEsError(indices, error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,20 @@ import { FieldDescriptor } from '../../index_patterns_fetcher';
* @param {Function} callCluster bound function for accessing an es client
* @param {Array} [indices=[]] the list of indexes to check
* @param {Array} [metaFields=[]] the list of internal fields to include
* @param {Object} fieldCapsOptions
* @return {Promise<Array<FieldDescriptor>>}
*/
export async function getFieldCapabilities(
callCluster: LegacyAPICaller,
indices: string | string[] = [],
metaFields: string[] = []
metaFields: string[] = [],
fieldCapsOptions?: { allowNoIndices: boolean }
) {
const esFieldCaps: FieldCapsResponse = await callFieldCapsApi(callCluster, indices);
const esFieldCaps: FieldCapsResponse = await callFieldCapsApi(
callCluster,
indices,
fieldCapsOptions
);
const fieldsFromFieldCapsByName = keyBy(readFieldCapsResponse(esFieldCaps), 'name');

const allFieldsUnsorted = Object.keys(fieldsFromFieldCapsByName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ export function Visualization(props) {
const { visData, model } = props;
// Show the error panel
const error = _.get(visData, `${model.id}.error`);
if (_.get(error, 'error.type') === 'index_not_found_exception') {
const index = _.get(error, 'error.index');
error.message = `Index "${index}" is missing`;
}
if (error) {
return (
<div className={props.className}>
Expand Down
12 changes: 8 additions & 4 deletions src/plugins/vis_type_timeseries/server/lib/get_fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@
* specific language governing permissions and limitations
* under the License.
*/
import { uniqBy } from 'lodash';
import { uniqBy, get } from 'lodash';
import { first, map } from 'rxjs/operators';
import { KibanaRequest, RequestHandlerContext } from 'kibana/server';

// @ts-ignore
import { getIndexPatternObject } from './vis_data/helpers/get_index_pattern';
import { indexPatterns } from '../../../data/server';
import { Framework } from '../plugin';
import { IndexPatternFieldDescriptor, IndexPatternsFetcher } from '../../../data/server';
Expand Down Expand Up @@ -73,7 +71,13 @@ export async function getFields(
.toPromise();
},
};
const { indexPatternString } = await getIndexPatternObject(reqFacade, indexPattern);
let indexPatternString = indexPattern;

if (!indexPatternString) {
const index = await reqFacade.getUiSettingsService().get('defaultIndex');
indexPatternString = get(index, 'title', '');
}

const {
searchStrategy,
capabilities,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export class AbstractSearchStrategy {

return await indexPatternsService!.getFieldsForWildcard({
pattern: indexPattern,
fieldCapsOptions: { allowNoIndices: true },
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@
* under the License.
*/

import { get } from 'lodash';

const DEFAULT_TIME_FIELD = '@timestamp';

export function getIntervalAndTimefield(panel, series = {}, indexPatternObject) {
const getDefaultTimeField = () => get(indexPatternObject, 'timeFieldName', DEFAULT_TIME_FIELD);
const getDefaultTimeField = () => indexPatternObject?.timeFieldName ?? DEFAULT_TIME_FIELD;

const timeField =
(series.override_index_pattern && series.series_time_field) ||
Expand Down

0 comments on commit 14cd01c

Please sign in to comment.