diff --git a/pkg/services/searchV2/http.go b/pkg/services/searchV2/http.go index d9b258dd4a9..51f5c5e5b7a 100644 --- a/pkg/services/searchV2/http.go +++ b/pkg/services/searchV2/http.go @@ -63,11 +63,12 @@ func (s *searchHTTPService) doQuery(c *models.ReqContext) response.Response { return response.Error(500, "error handling search request", resp.Error) } - if len(resp.Frames) != 1 { - return response.Error(500, "invalid search response", errors.New("invalid search response")) + if len(resp.Frames) == 0 { + msg := "invalid search response" + return response.Error(500, msg, errors.New(msg)) } - bytes, err := resp.Frames[0].MarshalJSON() + bytes, err := resp.MarshalJSON() if err != nil { return response.Error(500, "error marshalling response", err) } diff --git a/public/app/features/search/service/bluge.ts b/public/app/features/search/service/bluge.ts index 147df79628f..bdeb9a7ecc5 100644 --- a/public/app/features/search/service/bluge.ts +++ b/public/app/features/search/service/bluge.ts @@ -1,6 +1,7 @@ import { ArrayVector, DataFrame, + DataFrameJSON, DataFrameView, getDisplayProcessor, SelectableValue, @@ -19,6 +20,10 @@ const loadingFrameName = 'Loading'; const searchURI = 'api/search-v2'; +type SearchAPIResponse = { + frames: DataFrameJSON[]; +}; + export class BlugeSearcher implements GrafanaSearcher { constructor(private fallbackSearcher: GrafanaSearcher) {} @@ -51,15 +56,19 @@ export class BlugeSearcher implements GrafanaSearcher { limit: 1, // 0 would be better, but is ignored by the backend }; - const frame = toDataFrame(await getBackendSrv().post(searchURI, req)); + const resp = await getBackendSrv().post(searchURI, req); + const frames = resp.frames.map((f) => toDataFrame(f)); - if (frame?.name === loadingFrameName) { + if (frames[0]?.name === loadingFrameName) { return this.fallbackSearcher.tags(query); } - if (frame.fields[0].name === 'tag') { - return getTermCountsFrom(frame); + for (const frame of frames) { + if (frame.fields[0].name === 'tag') { + return getTermCountsFrom(frame); + } } + return []; } @@ -92,9 +101,10 @@ export class BlugeSearcher implements GrafanaSearcher { limit: query.limit ?? firstPageSize, }; - const rsp = await getBackendSrv().post(searchURI, req); + const rsp = await getBackendSrv().post(searchURI, req); + const frames = rsp.frames.map((f) => toDataFrame(f)); - const first = rsp ? toDataFrame(rsp) : { fields: [], length: 0 }; + const first = frames.length ? toDataFrame(frames[0]) : { fields: [], length: 0 }; if (first.name === loadingFrameName) { return this.fallbackSearcher.search(query); @@ -138,13 +148,12 @@ export class BlugeSearcher implements GrafanaSearcher { if (from >= meta.count) { return; } - const frame = toDataFrame( - await getBackendSrv().post(searchURI, { - ...(req ?? {}), - from, - limit: nextPageSizes, - }) - ); + const resp = await getBackendSrv().post(searchURI, { + ...(req ?? {}), + from, + limit: nextPageSizes, + }); + const frame = toDataFrame(resp.frames[0]); if (!frame) { console.log('no results', frame);