Fix data streams returning 500 when there are no matching indices (#65152)

This commit is contained in:
Jen Huang 2020-05-04 16:04:04 -07:00 committed by GitHub
parent 02bdb50c82
commit bda8309864
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -21,11 +21,7 @@ export const getListHandler: RequestHandler = async (context, request, response)
// Get all matching indices and info about each
// This returns the top 100,000 indices (as buckets) by last activity
const {
aggregations: {
index: { buckets: indexResults },
},
} = await callCluster('search', {
const { aggregations } = await callCluster('search', {
index: DATA_STREAM_INDEX_PATTERN,
body: {
size: 0,
@ -90,6 +86,20 @@ export const getListHandler: RequestHandler = async (context, request, response)
},
});
const body: GetDataStreamsResponse = {
data_streams: [],
};
if (!(aggregations && aggregations.index && aggregations.index.buckets)) {
return response.ok({
body,
});
}
const {
index: { buckets: indexResults },
} = aggregations;
const dataStreams: DataStream[] = (indexResults as any[]).map(result => {
const {
key: indexName,
@ -110,9 +120,8 @@ export const getListHandler: RequestHandler = async (context, request, response)
};
});
const body: GetDataStreamsResponse = {
data_streams: dataStreams,
};
body.data_streams = dataStreams;
return response.ok({
body,
});