From 4bc86cf284339d7156cbdbdd43a82698813e22a1 Mon Sep 17 00:00:00 2001 From: Kawika Avilla Date: Wed, 26 Jan 2022 05:58:13 +0000 Subject: [PATCH] [BUG] Fix track total hits Issue: https://discuss.opendistrocommunity.dev/t/opensearch-dashboards-shows-10000-as-hits-total/8397 Signed-off-by: Kawika Avilla --- .../common/search/search_source/fetch/get_search_params.ts | 5 ++++- .../data/common/search/search_source/search_source.ts | 2 ++ src/plugins/data/common/search/search_source/types.ts | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/plugins/data/common/search/search_source/fetch/get_search_params.ts b/src/plugins/data/common/search/search_source/fetch/get_search_params.ts index 33617cf92fea..f32a7f593e6d 100644 --- a/src/plugins/data/common/search/search_source/fetch/get_search_params.ts +++ b/src/plugins/data/common/search/search_source/fetch/get_search_params.ts @@ -60,10 +60,13 @@ export function getSearchParamsFromRequest( ): ISearchRequestParams { const { getConfig } = dependencies; const searchParams = getSearchParams(getConfig); + // eslint-disable-next-line @typescript-eslint/naming-convention + const { track_total_hits, ...body } = searchRequest.body; return { index: searchRequest.index.title || searchRequest.index, - body: searchRequest.body, + body, + track_total_hits, ...searchParams, }; } diff --git a/src/plugins/data/common/search/search_source/search_source.ts b/src/plugins/data/common/search/search_source/search_source.ts index ea5d98670a66..e2516456f2b6 100644 --- a/src/plugins/data/common/search/search_source/search_source.ts +++ b/src/plugins/data/common/search/search_source/search_source.ts @@ -428,6 +428,8 @@ export class SearchSource { case 'type': case 'highlightAll': return key && data[key] == null && addToRoot(key, val); + case 'trackTotalHits': + return addToBody('track_total_hits', val); case 'searchAfter': return addToBody('search_after', val); case 'source': diff --git a/src/plugins/data/common/search/search_source/types.ts b/src/plugins/data/common/search/search_source/types.ts index 2ec4a31d94d8..c5bb4b5619be 100644 --- a/src/plugins/data/common/search/search_source/types.ts +++ b/src/plugins/data/common/search/search_source/types.ts @@ -89,6 +89,7 @@ export interface SearchSourceFields { sort?: OpenSearchQuerySortValue | OpenSearchQuerySortValue[]; highlight?: any; highlightAll?: boolean; + trackTotalHits?: boolean | number; /** * {@link AggConfigs} */