diff --git a/packages/kbn-es-types/src/search.ts b/packages/kbn-es-types/src/search.ts index 4c780fb2a2986..87f9dd15517c9 100644 --- a/packages/kbn-es-types/src/search.ts +++ b/packages/kbn-es-types/src/search.ts @@ -682,6 +682,7 @@ export interface ESQLSearchResponse { all_columns?: ESQLColumn[]; values: ESQLRow[]; took?: number; + _clusters?: estypes.ClusterStatistics; } export interface ESQLSearchParams { diff --git a/packages/kbn-search-response-warnings/src/extract_warnings.test.ts b/packages/kbn-search-response-warnings/src/extract_warnings.test.ts index cedf0546ae3a4..c5a1352c3d0f9 100644 --- a/packages/kbn-search-response-warnings/src/extract_warnings.test.ts +++ b/packages/kbn-search-response-warnings/src/extract_warnings.test.ts @@ -9,6 +9,7 @@ import { estypes } from '@elastic/elasticsearch'; import type { Start as InspectorStartContract } from '@kbn/inspector-plugin/public'; +import type { ESQLSearchResponse } from '@kbn/es-types'; import type { RequestAdapter } from '@kbn/inspector-plugin/common/adapters/request'; import { extractWarnings } from './extract_warnings'; @@ -108,6 +109,22 @@ describe('extract search response warnings', () => { expect(warnings).toEqual([]); }); + + it('should not include warnings when there is no _clusters or _shards information', () => { + const warnings = extractWarnings( + { + took: 46, + all_columns: [{ name: 'field1', type: 'string' }], + columns: [{ name: 'field1', type: 'string' }], + values: [['value1']], + } as ESQLSearchResponse, + mockInspectorService, + mockRequestAdapter, + 'My request' + ); + + expect(warnings).toEqual([]); + }); }); describe('remote clusters', () => { diff --git a/packages/kbn-search-response-warnings/src/extract_warnings.ts b/packages/kbn-search-response-warnings/src/extract_warnings.ts index 7d53a954f7715..58e963c239b12 100644 --- a/packages/kbn-search-response-warnings/src/extract_warnings.ts +++ b/packages/kbn-search-response-warnings/src/extract_warnings.ts @@ -8,6 +8,7 @@ */ import { estypes } from '@elastic/elasticsearch'; +import type { ESQLSearchResponse } from '@kbn/es-types'; import type { Start as InspectorStartContract, RequestAdapter } from '@kbn/inspector-plugin/public'; import type { SearchResponseWarning } from './types'; @@ -15,7 +16,7 @@ import type { SearchResponseWarning } from './types'; * @internal */ export function extractWarnings( - rawResponse: estypes.SearchResponse, + rawResponse: estypes.SearchResponse | ESQLSearchResponse, inspectorService: InspectorStartContract, requestAdapter: RequestAdapter, requestName: string, @@ -23,11 +24,13 @@ export function extractWarnings( ): SearchResponseWarning[] { const warnings: SearchResponseWarning[] = []; + // ES|QL supports _clusters in case of CCS but doesnt support _shards and timed_out (yet) const isPartial = rawResponse._clusters ? rawResponse._clusters.partial > 0 || rawResponse._clusters.skipped > 0 || rawResponse._clusters.running > 0 - : rawResponse.timed_out || rawResponse._shards.failed > 0; + : ('timed_out' in rawResponse && rawResponse.timed_out) || + ('_shards' in rawResponse && rawResponse._shards.failed > 0); if (isPartial) { warnings.push({ type: 'incomplete', @@ -39,9 +42,10 @@ export function extractWarnings( status: 'partial', indices: '', took: rawResponse.took, - timed_out: rawResponse.timed_out, - _shards: rawResponse._shards, - failures: rawResponse._shards.failures, + timed_out: 'timed_out' in rawResponse && rawResponse.timed_out, + ...('_shards' in rawResponse + ? { _shards: rawResponse._shards, failures: rawResponse._shards.failures } + : {}), }, }, openInInspector: () => { diff --git a/packages/kbn-search-response-warnings/tsconfig.json b/packages/kbn-search-response-warnings/tsconfig.json index 6823ef5abf8a1..1f87892403a61 100644 --- a/packages/kbn-search-response-warnings/tsconfig.json +++ b/packages/kbn-search-response-warnings/tsconfig.json @@ -10,6 +10,7 @@ "@kbn/core", "@kbn/react-kibana-mount", "@kbn/core-i18n-browser", + "@kbn/es-types", ], "exclude": ["target/**/*"] }