Skip to content

Commit 8fb543c

Browse files
committed
[Search] Fix content Indices documents error on paginate (#219471)
Initially added fix in `8.17` branch in [PR](#219411), but need this change in `main`, `8.18`, `8.19` & `9.0.0` and the file's paths are different in all versions(main, 8.18/8.19, 8.17, 9.0.0). Created this new PR, adding fix in `main` & will try to backport to other versions. ## Summary When `track_total_hits` is not provided to `fetchSearchResults`, the value is set to `false`. As a result, the `search` api does not include total hit count in its response. Thus, the total count of hit is 0 and onPaginate results in error. This PR sets `track_total_hits` as an optional argument in `fetchSearchResults` **Note** One other option would be to set `track_total_hits` to true but, based on this [documentation](https://www.elastic.co/docs/solutions/search/the-search-api#track-total-hits) setting `track_total_hits` to true would affect query performance. ``` Setting track_total_hits to true will cause Elasticsearch to return exact hit counts, which could hurt query performance because it disables the [Max WAND](https://www.elastic.co/blog/faster-retrieval-of-top-hits-in-elasticsearch-with-block-max-wand) optimization. ```` https://github.com/user-attachments/assets/4284e88f-2614-4fbe-a0eb-1980355f5bff ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios (cherry picked from commit 69d7124)
1 parent 2e6942c commit 8fb543c

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

packages/kbn-search-index-documents/lib/fetch_search_results.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ describe('fetchSearchResults lib function', () => {
8888
index: indexName,
8989
q: query,
9090
size: DEFAULT_DOCS_PER_PAGE,
91-
track_total_hits: false,
91+
track_total_hits: undefined,
9292
});
9393
});
9494

@@ -110,7 +110,7 @@ describe('fetchSearchResults lib function', () => {
110110
index: indexName,
111111
q: '\\"yellow banana\\"',
112112
size: DEFAULT_DOCS_PER_PAGE,
113-
track_total_hits: false,
113+
track_total_hits: undefined,
114114
});
115115
});
116116

@@ -125,7 +125,7 @@ describe('fetchSearchResults lib function', () => {
125125
from: DEFAULT_FROM_VALUE,
126126
index: indexName,
127127
size: DEFAULT_DOCS_PER_PAGE,
128-
track_total_hits: false,
128+
track_total_hits: undefined,
129129
});
130130
});
131131

@@ -153,7 +153,7 @@ describe('fetchSearchResults lib function', () => {
153153
index: indexName,
154154
q: query,
155155
size: DEFAULT_DOCS_PER_PAGE,
156-
track_total_hits: false,
156+
track_total_hits: undefined,
157157
});
158158
});
159159

packages/kbn-search-index-documents/lib/fetch_search_results.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export const fetchSearchResults = async (
1919
query?: string,
2020
from: number = 0,
2121
size: number = DEFAULT_DOCS_PER_PAGE,
22-
trackTotalHits: boolean = false
22+
trackTotalHits?: boolean
2323
): Promise<Paginate<SearchHit>> => {
2424
const result = await fetchWithPagination(
2525
async () =>

0 commit comments

Comments
 (0)