Skip to content

Commit 69d7124

Browse files
authored
[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
1 parent 125fc2a commit 69d7124

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

x-pack/platform/packages/shared/kbn-search-index-documents/lib/fetch_search_results.test.ts

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

@@ -108,7 +108,7 @@ describe('fetchSearchResults lib function', () => {
108108
index: indexName,
109109
q: '\\"yellow banana\\"',
110110
size: DEFAULT_DOCS_PER_PAGE,
111-
track_total_hits: false,
111+
track_total_hits: undefined,
112112
});
113113
});
114114

@@ -123,7 +123,7 @@ describe('fetchSearchResults lib function', () => {
123123
from: DEFAULT_FROM_VALUE,
124124
index: indexName,
125125
size: DEFAULT_DOCS_PER_PAGE,
126-
track_total_hits: false,
126+
track_total_hits: undefined,
127127
});
128128
});
129129

@@ -151,7 +151,7 @@ describe('fetchSearchResults lib function', () => {
151151
index: indexName,
152152
q: query,
153153
size: DEFAULT_DOCS_PER_PAGE,
154-
track_total_hits: false,
154+
track_total_hits: undefined,
155155
});
156156
});
157157

x-pack/platform/packages/shared/kbn-search-index-documents/lib/fetch_search_results.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const fetchSearchResults = async (
1717
query?: string,
1818
from: number = 0,
1919
size: number = DEFAULT_DOCS_PER_PAGE,
20-
trackTotalHits: boolean = false
20+
trackTotalHits?: boolean
2121
): Promise<Paginate<SearchHit>> => {
2222
return fetchWithPagination(
2323
() =>

0 commit comments

Comments
 (0)