Skip to content

Commit

Permalink
Fix indexField query to not crash if no indexes (#23628)
Browse files Browse the repository at this point in the history
* do not crash if you do not have indexes for the indexfield

* do not return an empty arrays if one of the indexes are here

* no need to break the code here
  • Loading branch information
XavierM authored Sep 29, 2018
1 parent faf89e4 commit aac34a1
Showing 1 changed file with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,19 @@ export class FrameworkFieldsAdapter implements FieldsAdapter {
indices: string[]
): Promise<IndexFieldDescriptor[]> {
const indexPatternsService = this.framework.getIndexPatternsService(request);
const response = await indexPatternsService.getFieldsForWildcard({
pattern: indices,
});

return response;
const IndexFieldResponses = await Promise.all(
indices.map(indice =>
indexPatternsService.getFieldsForWildcard({ pattern: indice }).catch(error => {
if (error && error.output && error.output.statusCode === 404) {
return [];
}
throw error;
})
)
);
return IndexFieldResponses.reduce(
(indexFields, indexFieldResponse) => [...indexFields, ...indexFieldResponse],
[] as IndexFieldDescriptor[]
);
}
}

0 comments on commit aac34a1

Please sign in to comment.