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');
|
expect(searchParams.preference).toBe('aaa');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('extracts track total hits', () => {
|
test('extracts track total hits from request', () => {
|
||||||
const getConfig = getConfigStub({
|
const getConfig = getConfigStub({
|
||||||
[UI_SETTINGS.COURIER_SET_REQUEST_PREFERENCE]: 'custom',
|
[UI_SETTINGS.COURIER_SET_REQUEST_PREFERENCE]: 'custom',
|
||||||
[UI_SETTINGS.COURIER_CUSTOM_REQUEST_PREFERENCE]: 'aaa',
|
[UI_SETTINGS.COURIER_CUSTOM_REQUEST_PREFERENCE]: 'aaa',
|
||||||
|
@ -44,6 +44,27 @@ describe('getSearchParams', () => {
|
||||||
expect(searchParams.query).toStrictEqual([{ query: '123', language: 'kql' }]);
|
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', () => {
|
test('sets expand_wildcards=all if data view has allowHidden=true', () => {
|
||||||
const getConfig = getConfigStub({
|
const getConfig = getConfigStub({
|
||||||
[UI_SETTINGS.COURIER_SET_REQUEST_PREFERENCE]: 'custom',
|
[UI_SETTINGS.COURIER_SET_REQUEST_PREFERENCE]: 'custom',
|
||||||
|
|
|
@ -35,10 +35,12 @@ export function getSearchParamsFromRequest(
|
||||||
const searchParams = { preference: getEsPreference(getConfig) };
|
const searchParams = { preference: getEsPreference(getConfig) };
|
||||||
const dataView = typeof searchRequest.index !== 'string' ? searchRequest.index : undefined;
|
const dataView = typeof searchRequest.index !== 'string' ? searchRequest.index : undefined;
|
||||||
const index = dataView?.title ?? `${searchRequest.index}`;
|
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)
|
// @ts-expect-error elasticsearch@9.0.0 `query` types don't match (it seems like it's been wrong here for a while)
|
||||||
return {
|
return {
|
||||||
...searchRequest,
|
...searchRequest,
|
||||||
|
track_total_hits: trackTotalHits,
|
||||||
index,
|
index,
|
||||||
...(dataView?.getAllowHidden() && { expand_wildcards: 'all' }),
|
...(dataView?.getAllowHidden() && { expand_wildcards: 'all' }),
|
||||||
...searchParams,
|
...searchParams,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue