mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
[data.search] Respect search request track_total_hits
value (#215245)
## Summary Fixes https://github.com/elastic/kibana/issues/212946. Updates `getSearchParamsFromRequest` to respect `track_total_hits` if it is included in the `body` portion of the search request. ### 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
This commit is contained in:
parent
11749b6855
commit
fab3060544
2 changed files with 24 additions and 1 deletions
|
@ -26,7 +26,7 @@ describe('getSearchParams', () => {
|
|||
expect(searchParams.preference).toBe('aaa');
|
||||
});
|
||||
|
||||
test('extracts track total hits', () => {
|
||||
test('extracts track total hits from request', () => {
|
||||
const getConfig = getConfigStub({
|
||||
[UI_SETTINGS.COURIER_SET_REQUEST_PREFERENCE]: 'custom',
|
||||
[UI_SETTINGS.COURIER_CUSTOM_REQUEST_PREFERENCE]: 'aaa',
|
||||
|
@ -44,6 +44,27 @@ describe('getSearchParams', () => {
|
|||
expect(searchParams.query).toStrictEqual([{ query: '123', language: 'kql' }]);
|
||||
});
|
||||
|
||||
test('extracts track total hits from body', () => {
|
||||
const getConfig = getConfigStub({
|
||||
[UI_SETTINGS.COURIER_SET_REQUEST_PREFERENCE]: 'custom',
|
||||
[UI_SETTINGS.COURIER_CUSTOM_REQUEST_PREFERENCE]: 'aaa',
|
||||
});
|
||||
const searchParams = getSearchParamsFromRequest(
|
||||
{
|
||||
body: {
|
||||
query: { bool: { filter: [] } },
|
||||
track_total_hits: false,
|
||||
size: 500,
|
||||
},
|
||||
index: 'abc',
|
||||
},
|
||||
{ getConfig }
|
||||
);
|
||||
expect(searchParams.index).toBe('abc');
|
||||
expect(searchParams.track_total_hits).toBe(false);
|
||||
expect(searchParams.query).toMatchInlineSnapshot(`undefined`);
|
||||
});
|
||||
|
||||
test('sets expand_wildcards=all if data view has allowHidden=true', () => {
|
||||
const getConfig = getConfigStub({
|
||||
[UI_SETTINGS.COURIER_SET_REQUEST_PREFERENCE]: 'custom',
|
||||
|
|
|
@ -35,10 +35,12 @@ export function getSearchParamsFromRequest(
|
|||
const searchParams = { preference: getEsPreference(getConfig) };
|
||||
const dataView = typeof searchRequest.index !== 'string' ? searchRequest.index : undefined;
|
||||
const index = dataView?.title ?? `${searchRequest.index}`;
|
||||
const trackTotalHits = searchRequest.track_total_hits ?? searchRequest.body.track_total_hits;
|
||||
|
||||
// @ts-expect-error elasticsearch@9.0.0 `query` types don't match (it seems like it's been wrong here for a while)
|
||||
return {
|
||||
...searchRequest,
|
||||
track_total_hits: trackTotalHits,
|
||||
index,
|
||||
...(dataView?.getAllowHidden() && { expand_wildcards: 'all' }),
|
||||
...searchParams,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue