diff --git a/x-pack/plugins/monitoring/server/lib/cluster/get_clusters_stats.ts b/x-pack/plugins/monitoring/server/lib/cluster/get_clusters_stats.ts index ff82c3ba3f2f8..609c8fb2089de 100644 --- a/x-pack/plugins/monitoring/server/lib/cluster/get_clusters_stats.ts +++ b/x-pack/plugins/monitoring/server/lib/cluster/get_clusters_stats.ts @@ -87,7 +87,7 @@ function fetchClusterStats(req: LegacyRequest, esIndexPattern: string, clusterUu * @return {Array} Objects representing each cluster. */ export function handleClusterStats(response: ElasticsearchResponse) { - const hits = response.hits?.hits ?? []; + const hits = response?.hits?.hits ?? []; return hits .map((hit) => { diff --git a/x-pack/plugins/monitoring/server/lib/elasticsearch/indices/get_indices.ts b/x-pack/plugins/monitoring/server/lib/elasticsearch/indices/get_indices.ts index 6d38cc7824ae4..bf19fcf8978e9 100644 --- a/x-pack/plugins/monitoring/server/lib/elasticsearch/indices/get_indices.ts +++ b/x-pack/plugins/monitoring/server/lib/elasticsearch/indices/get_indices.ts @@ -26,7 +26,7 @@ export function handleResponse( shardStats: any ) { // map the hits - const hits = resp.hits?.hits ?? []; + const hits = resp?.hits?.hits ?? []; return hits.map((hit) => { const stats = hit._source.index_stats; const earliestStats = hit.inner_hits?.earliest?.hits?.hits[0]?._source.index_stats; diff --git a/x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/handle_response.ts b/x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/handle_response.ts index 961a45fe131a2..3e248a06318da 100644 --- a/x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/handle_response.ts +++ b/x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/handle_response.ts @@ -22,8 +22,8 @@ import { ElasticsearchResponse, ElasticsearchModifiedSource } from '../../../../ */ export function handleResponse( response: ElasticsearchResponse, - clusterStats: ElasticsearchModifiedSource, - nodesShardCount: { nodes: { [nodeId: string]: { shardCount: number } } }, + clusterStats: ElasticsearchModifiedSource | undefined, + nodesShardCount: { nodes: { [nodeId: string]: { shardCount: number } } } | undefined, pageOfNodes: Array<{ uuid: string }>, timeOptions = {} ) { diff --git a/x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/map_nodes_info.ts b/x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/map_nodes_info.ts index 0f166c873dac1..a2e80c9ca1d96 100644 --- a/x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/map_nodes_info.ts +++ b/x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/map_nodes_info.ts @@ -22,10 +22,10 @@ import { */ export function mapNodesInfo( nodeHits: ElasticsearchResponseHit[], - clusterStats: ElasticsearchModifiedSource, - nodesShardCount: { nodes: { [nodeId: string]: { shardCount: number } } } + clusterStats?: ElasticsearchModifiedSource, + nodesShardCount?: { nodes: { [nodeId: string]: { shardCount: number } } } ) { - const clusterState = clusterStats.cluster_state ?? { nodes: {} }; + const clusterState = clusterStats?.cluster_state ?? { nodes: {} }; return nodeHits.reduce((prev, node) => { const sourceNode = node._source.source_node || node._source.elasticsearch?.node; @@ -50,7 +50,7 @@ export function mapNodesInfo( isOnline, nodeTypeLabel, nodeTypeClass, - shardCount: nodesShardCount.nodes[uuid]?.shardCount ?? 0, + shardCount: nodesShardCount?.nodes[uuid]?.shardCount ?? 0, }, }; }, {}); diff --git a/x-pack/plugins/monitoring/server/lib/logstash/get_node_info.ts b/x-pack/plugins/monitoring/server/lib/logstash/get_node_info.ts index ead8764607786..cdf2277424002 100644 --- a/x-pack/plugins/monitoring/server/lib/logstash/get_node_info.ts +++ b/x-pack/plugins/monitoring/server/lib/logstash/get_node_info.ts @@ -9,7 +9,8 @@ import { merge } from 'lodash'; import { checkParam } from '../error_missing_required'; // @ts-ignore import { calculateAvailability } from '../calculate_availability'; -import { LegacyRequest, ElasticsearchResponse } from '../../types'; +import { LegacyRequest } from '../../types'; +import { ElasticsearchResponse } from '../../../common/types/es'; export function handleResponse(resp: ElasticsearchResponse) { const source = resp.hits?.hits[0]?._source?.logstash_stats; diff --git a/x-pack/plugins/monitoring/server/lib/logstash/get_pipeline_state_document.ts b/x-pack/plugins/monitoring/server/lib/logstash/get_pipeline_state_document.ts index 96419ceb4cc70..1556b44f73804 100644 --- a/x-pack/plugins/monitoring/server/lib/logstash/get_pipeline_state_document.ts +++ b/x-pack/plugins/monitoring/server/lib/logstash/get_pipeline_state_document.ts @@ -8,7 +8,8 @@ import { createQuery } from '../create_query'; // @ts-ignore import { LogstashMetric } from '../metrics'; -import { LegacyRequest, ElasticsearchResponse } from '../../types'; +import { LegacyRequest } from '../../types'; +import { ElasticsearchResponse } from '../../../common/types/es'; export async function getPipelineStateDocument( req: LegacyRequest,