mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
Fix track total hits not sent correctly from SearchSource (#91909)
* Move track total hits to root level * code review * doc
This commit is contained in:
parent
2df74a1088
commit
b1d76cedac
8 changed files with 46 additions and 3 deletions
|
@ -32,6 +32,7 @@ export interface SearchSourceFields
|
|||
| [source](./kibana-plugin-plugins-data-public.searchsourcefields.source.md) | <code>NameList</code> | |
|
||||
| [terminate\_after](./kibana-plugin-plugins-data-public.searchsourcefields.terminate_after.md) | <code>number</code> | |
|
||||
| [timeout](./kibana-plugin-plugins-data-public.searchsourcefields.timeout.md) | <code>string</code> | |
|
||||
| [trackTotalHits](./kibana-plugin-plugins-data-public.searchsourcefields.tracktotalhits.md) | <code>boolean | number</code> | |
|
||||
| [type](./kibana-plugin-plugins-data-public.searchsourcefields.type.md) | <code>string</code> | |
|
||||
| [version](./kibana-plugin-plugins-data-public.searchsourcefields.version.md) | <code>boolean</code> | |
|
||||
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [SearchSourceFields](./kibana-plugin-plugins-data-public.searchsourcefields.md) > [trackTotalHits](./kibana-plugin-plugins-data-public.searchsourcefields.tracktotalhits.md)
|
||||
|
||||
## SearchSourceFields.trackTotalHits property
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
trackTotalHits?: boolean | number;
|
||||
```
|
|
@ -190,7 +190,8 @@ export const SearchExamplesApp = ({
|
|||
.setField('index', indexPattern)
|
||||
.setField('filter', filters)
|
||||
.setField('query', query)
|
||||
.setField('fields', selectedFields.length ? selectedFields.map((f) => f.name) : ['*']);
|
||||
.setField('fields', selectedFields.length ? selectedFields.map((f) => f.name) : ['*'])
|
||||
.setField('trackTotalHits', 100);
|
||||
|
||||
if (selectedNumericField) {
|
||||
searchSource.setField('aggs', () => {
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
import { UI_SETTINGS } from '../../../constants';
|
||||
import { GetConfigFn } from '../../../types';
|
||||
import { getSearchParams } from './get_search_params';
|
||||
import { getSearchParams, getSearchParamsFromRequest } from './get_search_params';
|
||||
|
||||
function getConfigStub(config: any = {}): GetConfigFn {
|
||||
return (key) => config[key];
|
||||
|
@ -23,4 +23,26 @@ describe('getSearchParams', () => {
|
|||
const searchParams = getSearchParams(config);
|
||||
expect(searchParams.preference).toBe('aaa');
|
||||
});
|
||||
|
||||
test('extracts track total hits', () => {
|
||||
const getConfig = getConfigStub({
|
||||
[UI_SETTINGS.COURIER_SET_REQUEST_PREFERENCE]: 'custom',
|
||||
[UI_SETTINGS.COURIER_CUSTOM_REQUEST_PREFERENCE]: 'aaa',
|
||||
});
|
||||
const searchParams = getSearchParamsFromRequest(
|
||||
{
|
||||
index: 'abc',
|
||||
body: {
|
||||
query: 123,
|
||||
track_total_hits: true,
|
||||
},
|
||||
},
|
||||
{ getConfig }
|
||||
);
|
||||
expect(searchParams.index).toBe('abc');
|
||||
expect(searchParams.track_total_hits).toBe(true);
|
||||
expect(searchParams.body).toStrictEqual({
|
||||
query: 123,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -36,10 +36,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,
|
||||
};
|
||||
}
|
||||
|
|
|
@ -429,6 +429,8 @@ export class SearchSource {
|
|||
return key && data[key] == null && addToRoot(key, val);
|
||||
case 'searchAfter':
|
||||
return addToBody('search_after', val);
|
||||
case 'trackTotalHits':
|
||||
return addToBody('track_total_hits', val);
|
||||
case 'source':
|
||||
return addToBody('_source', val);
|
||||
case 'sort':
|
||||
|
|
|
@ -74,6 +74,7 @@ export interface SearchSourceFields {
|
|||
sort?: EsQuerySortValue | EsQuerySortValue[];
|
||||
highlight?: any;
|
||||
highlightAll?: boolean;
|
||||
trackTotalHits?: boolean | number;
|
||||
/**
|
||||
* {@link AggConfigs}
|
||||
*/
|
||||
|
|
|
@ -2447,6 +2447,8 @@ export interface SearchSourceFields {
|
|||
// (undocumented)
|
||||
timeout?: string;
|
||||
// (undocumented)
|
||||
trackTotalHits?: boolean | number;
|
||||
// (undocumented)
|
||||
type?: string;
|
||||
// (undocumented)
|
||||
version?: boolean;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue