diff --git a/changelogs/fragments/8781.yml b/changelogs/fragments/8781.yml new file mode 100644 index 000000000000..cee2381aadf5 --- /dev/null +++ b/changelogs/fragments/8781.yml @@ -0,0 +1,2 @@ +fix: +- Update async search response type ([#8781](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/8781)) \ No newline at end of file diff --git a/src/plugins/query_enhancements/server/search/ppl_async_search_strategy.ts b/src/plugins/query_enhancements/server/search/ppl_async_search_strategy.ts index ede0d51b62c7..309c5fd522b6 100644 --- a/src/plugins/query_enhancements/server/search/ppl_async_search_strategy.ts +++ b/src/plugins/query_enhancements/server/search/ppl_async_search_strategy.ts @@ -58,22 +58,22 @@ export const pplAsyncSearchStrategyProvider = ( } as IDataFrameResponse; } else { request.params = { queryId: inProgressQueryId }; - const queryStatusResponse: any = await pplAsyncJobsFacet.describeQuery(context, request); + const queryStatusResponse = await pplAsyncJobsFacet.describeQuery(context, request); if (!queryStatusResponse.success) handleFacetError(queryStatusResponse); - const queryStatus = queryStatusResponse?.data?.status; + const queryStatus = queryStatusResponse.data?.status; logger.info(`pplAsyncSearchStrategy: JOB: ${inProgressQueryId} - STATUS: ${queryStatus}`); if (queryStatus?.toUpperCase() === 'SUCCESS') { const dataFrame = createDataFrame({ name: query.dataset?.id, - schema: queryStatusResponse.data.schema, + schema: queryStatusResponse.data?.schema, meta: { ...pollQueryResultsParams }, fields: getFields(queryStatusResponse), }); - dataFrame.size = queryStatusResponse.data.datarows.length; + dataFrame.size = queryStatusResponse.data?.datarows.length; return { type: DATA_FRAME_TYPES.POLLING, @@ -85,7 +85,7 @@ export const pplAsyncSearchStrategyProvider = ( type: DATA_FRAME_TYPES.POLLING, status: 'failed', body: { - error: `JOB: ${inProgressQueryId} failed: ${queryStatusResponse.data.error}`, + error: `JOB: ${inProgressQueryId} failed: ${queryStatusResponse.data?.error}`, }, } as IDataFrameResponse; } diff --git a/src/plugins/query_enhancements/server/search/sql_async_search_strategy.ts b/src/plugins/query_enhancements/server/search/sql_async_search_strategy.ts index eda7997c1b63..bc25f69a70f6 100644 --- a/src/plugins/query_enhancements/server/search/sql_async_search_strategy.ts +++ b/src/plugins/query_enhancements/server/search/sql_async_search_strategy.ts @@ -3,18 +3,18 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { SharedGlobalConfig, Logger, ILegacyClusterClient } from 'opensearch-dashboards/server'; +import { ILegacyClusterClient, Logger, SharedGlobalConfig } from 'opensearch-dashboards/server'; import { Observable } from 'rxjs'; -import { ISearchStrategy, SearchUsage } from '../../../data/server'; import { + createDataFrame, DATA_FRAME_TYPES, IDataFrameResponse, IOpenSearchDashboardsSearchRequest, Query, - createDataFrame, } from '../../../data/common'; -import { Facet } from '../utils'; +import { ISearchStrategy, SearchUsage } from '../../../data/server'; import { buildQueryStatusConfig, getFields, handleFacetError, SEARCH_STRATEGY } from '../../common'; +import { Facet } from '../utils'; export const sqlAsyncSearchStrategyProvider = ( config$: Observable, @@ -58,22 +58,22 @@ export const sqlAsyncSearchStrategyProvider = ( } as IDataFrameResponse; } else { request.params = { queryId: inProgressQueryId }; - const queryStatusResponse: any = await sqlAsyncJobsFacet.describeQuery(context, request); + const queryStatusResponse = await sqlAsyncJobsFacet.describeQuery(context, request); if (!queryStatusResponse.success) handleFacetError(queryStatusResponse); - const queryStatus = queryStatusResponse?.data?.status; + const queryStatus = queryStatusResponse.data?.status; logger.info(`sqlAsyncSearchStrategy: JOB: ${inProgressQueryId} - STATUS: ${queryStatus}`); if (queryStatus?.toUpperCase() === 'SUCCESS') { const dataFrame = createDataFrame({ name: query.dataset?.id, - schema: queryStatusResponse.data.schema, + schema: queryStatusResponse.data?.schema, meta: { ...pollQueryResultsParams }, fields: getFields(queryStatusResponse), }); - dataFrame.size = queryStatusResponse.data.datarows.length; + dataFrame.size = queryStatusResponse.data?.datarows.length; return { type: DATA_FRAME_TYPES.POLLING, @@ -85,7 +85,7 @@ export const sqlAsyncSearchStrategyProvider = ( type: DATA_FRAME_TYPES.POLLING, status: 'failed', body: { - error: `JOB: ${inProgressQueryId} failed: ${queryStatusResponse.data.error}`, + error: `JOB: ${inProgressQueryId} failed: ${queryStatusResponse.data?.error}`, }, } as IDataFrameResponse; }