From 0ad9745568a0880be0a102de3ecb1271473dc58c Mon Sep 17 00:00:00 2001 From: Joshua Li Date: Tue, 29 Oct 2024 16:45:23 +0000 Subject: [PATCH 1/2] [Discover] fix error handling in query enhancement facet Signed-off-by: Joshua Li --- src/plugins/query_enhancements/common/utils.ts | 3 ++- .../query_enhancements/server/search/ppl_search_strategy.ts | 1 + src/plugins/query_enhancements/server/utils/facet.ts | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/plugins/query_enhancements/common/utils.ts b/src/plugins/query_enhancements/common/utils.ts index 0d2697dc2135..2ac1cf430f5c 100644 --- a/src/plugins/query_enhancements/common/utils.ts +++ b/src/plugins/query_enhancements/common/utils.ts @@ -44,7 +44,8 @@ export const removeKeyword = (queryString: string | undefined) => { export const handleFacetError = (response: any) => { const error = new Error(response.data.body ?? response.data); - error.name = response.data.status ?? response.status; + error.name = response.data.status ?? response.status ?? response.data.statusCode; + (error as any).status = error.name; throw error; }; diff --git a/src/plugins/query_enhancements/server/search/ppl_search_strategy.ts b/src/plugins/query_enhancements/server/search/ppl_search_strategy.ts index 501e2287411b..d71ae6810fad 100644 --- a/src/plugins/query_enhancements/server/search/ppl_search_strategy.ts +++ b/src/plugins/query_enhancements/server/search/ppl_search_strategy.ts @@ -56,6 +56,7 @@ export const pplSearchStrategyProvider = ( for (const [key, aggQueryString] of Object.entries(aggConfig.qs)) { request.body.query.query = aggQueryString; const rawAggs: any = await pplFacet.describeQuery(context, request); + if (!rawAggs.success) handleFacetError(rawResponse); (dataFrame as IDataFrameWithAggs).aggs = {}; (dataFrame as IDataFrameWithAggs).aggs[key] = rawAggs.data.datarows?.map((hit: any) => { return { diff --git a/src/plugins/query_enhancements/server/utils/facet.ts b/src/plugins/query_enhancements/server/utils/facet.ts index 0b6dd52407cd..a080b8833fb7 100644 --- a/src/plugins/query_enhancements/server/utils/facet.ts +++ b/src/plugins/query_enhancements/server/utils/facet.ts @@ -100,7 +100,7 @@ export class Facet { const response = this.useJobs ? await this.fetchJobs(context, request, this.endpoint) : await this.fetch(context, request, this.endpoint); - if (!this.shimResponse) return response; + if (response.success === false || !this.shimResponse) return response; const { format: dataType } = request.body; const shimFunctions: { [key: string]: (data: any) => any } = { From 6dd9ad6fdc850227a07647298a93593972a261e4 Mon Sep 17 00:00:00 2001 From: "opensearch-changeset-bot[bot]" <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com> Date: Tue, 29 Oct 2024 17:09:59 +0000 Subject: [PATCH 2/2] Changeset file for PR #8743 created/updated --- changelogs/fragments/8743.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 changelogs/fragments/8743.yml diff --git a/changelogs/fragments/8743.yml b/changelogs/fragments/8743.yml new file mode 100644 index 000000000000..4ef81b73020b --- /dev/null +++ b/changelogs/fragments/8743.yml @@ -0,0 +1,2 @@ +fix: +- Fix error handling in query enhancement facet ([#8743](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/8743)) \ No newline at end of file