diff --git a/src/plugins/data/server/index_patterns/index_patterns_api_client.ts b/src/plugins/data/server/index_patterns/index_patterns_api_client.ts index 941a90f500ab6..0ed84d4eee3b7 100644 --- a/src/plugins/data/server/index_patterns/index_patterns_api_client.ts +++ b/src/plugins/data/server/index_patterns/index_patterns_api_client.ts @@ -12,6 +12,7 @@ import { IIndexPatternsApiClient, GetFieldsOptionsTimePattern, } from '../../common/index_patterns/types'; +import { IndexPatternMissingIndices } from '../../common/index_patterns/lib'; import { IndexPatternsFetcher } from './fetcher'; export class IndexPatternsApiServer implements IIndexPatternsApiClient { @@ -27,12 +28,23 @@ export class IndexPatternsApiServer implements IIndexPatternsApiClient { allowNoIndex, }: GetFieldsOptions) { const indexPatterns = new IndexPatternsFetcher(this.esClient, allowNoIndex); - return await indexPatterns.getFieldsForWildcard({ - pattern, - metaFields, - type, - rollupIndex, - }); + return await indexPatterns + .getFieldsForWildcard({ + pattern, + metaFields, + type, + rollupIndex, + }) + .catch((err) => { + if ( + err.output.payload.statusCode === 404 && + err.output.payload.code === 'no_matching_indices' + ) { + throw new IndexPatternMissingIndices(pattern); + } else { + throw err; + } + }); } async getFieldsForTimePattern(options: GetFieldsOptionsTimePattern) { const indexPatterns = new IndexPatternsFetcher(this.esClient); diff --git a/x-pack/plugins/maps/server/maps_telemetry/maps_telemetry.ts b/x-pack/plugins/maps/server/maps_telemetry/maps_telemetry.ts index bf180c514c56f..569f7e17896f2 100644 --- a/x-pack/plugins/maps/server/maps_telemetry/maps_telemetry.ts +++ b/x-pack/plugins/maps/server/maps_telemetry/maps_telemetry.ts @@ -125,8 +125,7 @@ async function isFieldGeoShape( if (!indexPattern) { return false; } - const fieldsForIndexPattern = await indexPatternsService.getFieldsForIndexPattern(indexPattern); - return fieldsForIndexPattern.some( + return indexPattern.fields.some( (fieldDescriptor: IFieldType) => fieldDescriptor.name && fieldDescriptor.name === geoField! ); } @@ -192,13 +191,9 @@ async function filterIndexPatternsByField(fields: string[]) { await Promise.all( indexPatternIds.map(async (indexPatternId: string) => { const indexPattern = await indexPatternsService.get(indexPatternId); - const fieldsForIndexPattern = await indexPatternsService.getFieldsForIndexPattern( - indexPattern - ); const containsField = fields.some((field: string) => - fieldsForIndexPattern.some( - (fieldDescriptor: IFieldType) => - fieldDescriptor.esTypes && fieldDescriptor.esTypes.includes(field) + indexPattern.fields.some( + (fieldDescriptor) => fieldDescriptor.esTypes && fieldDescriptor.esTypes.includes(field) ) ); if (containsField) {