Fix data streams returning 500 when there are no matching indices (#65152)
This commit is contained in:
parent
02bdb50c82
commit
bda8309864
|
@ -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,
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue