diff --git a/src/plugins/data/common/search/search_source/normalize_sort_request.test.ts b/src/plugins/data/common/search/search_source/normalize_sort_request.test.ts index 134886efe9e0c..265d8c085b7e9 100644 --- a/src/plugins/data/common/search/search_source/normalize_sort_request.test.ts +++ b/src/plugins/data/common/search/search_source/normalize_sort_request.test.ts @@ -67,7 +67,7 @@ describe('SearchSource#normalizeSortRequest', function () { it('should append default sort options', function () { const defaultSortOptions = { - unmapped_type: 'boolean', + unmapped_type: 'boolean' as 'boolean', }; const result = normalizeSortRequest( [{ someField: SortDirection.desc }], diff --git a/src/plugins/data/common/search/search_source/normalize_sort_request.ts b/src/plugins/data/common/search/search_source/normalize_sort_request.ts index 5744b1fd53801..49cdd8ba289e3 100644 --- a/src/plugins/data/common/search/search_source/normalize_sort_request.ts +++ b/src/plugins/data/common/search/search_source/normalize_sort_request.ts @@ -6,13 +6,21 @@ * Side Public License, v 1. */ +import { estypes } from '@elastic/elasticsearch'; import type { DataView } from '@kbn/data-views-plugin/common'; -import { EsQuerySortValue, SortOptions } from './types'; +import { EsQuerySortValue } from './types'; + +type FieldSortOptions = estypes.FieldSort & + estypes.ScoreSort & + estypes.GeoDistanceSort & + Omit & { + script?: estypes.ScriptSort['script']; + }; export function normalizeSortRequest( sortObject: EsQuerySortValue | EsQuerySortValue[], indexPattern: DataView | string | undefined, - defaultSortOptions: SortOptions = {} + defaultSortOptions: FieldSortOptions | string = {} ) { const sortArray: EsQuerySortValue[] = Array.isArray(sortObject) ? sortObject : [sortObject]; return sortArray.map(function (sortable) { @@ -28,7 +36,7 @@ export function normalizeSortRequest( function normalize( sortable: EsQuerySortValue, indexPattern: DataView | string | undefined, - defaultSortOptions: any + defaultSortOptions: FieldSortOptions | string ) { const [[sortField, sortOrder]] = Object.entries(sortable); const order = typeof sortOrder === 'object' ? sortOrder : { order: sortOrder }; @@ -52,13 +60,16 @@ function normalize( // FIXME: for unknown reason on the server this setting is serialized // https://github.com/elastic/kibana/issues/89902 if (typeof defaultSortOptions === 'string') { - defaultSortOptions = JSON.parse(defaultSortOptions); + defaultSortOptions = JSON.parse(defaultSortOptions) as FieldSortOptions; } // Don't include unmapped_type for _score field // eslint-disable-next-line @typescript-eslint/naming-convention const { unmapped_type, ...otherSortOptions } = defaultSortOptions; return { - [sortField]: { ...order, ...(sortField === '_score' ? otherSortOptions : defaultSortOptions) }, + [sortField]: { + ...order, + ...(sortField === '_score' ? otherSortOptions : defaultSortOptions), + }, }; } diff --git a/src/plugins/data/common/search/search_source/types.ts b/src/plugins/data/common/search/search_source/types.ts index 60c0d3713ec64..98cf431658e4c 100644 --- a/src/plugins/data/common/search/search_source/types.ts +++ b/src/plugins/data/common/search/search_source/types.ts @@ -39,11 +39,6 @@ export interface ISearchStartSearchSource createEmpty: () => ISearchSource; } -/** - * @deprecated use {@link estypes.SortResults} instead. - */ -export type EsQuerySearchAfter = [string | number, string | number]; - export enum SortDirection { asc = 'asc', desc = 'desc', @@ -178,53 +173,6 @@ export interface SearchSourceOptions { callParentStartHandlers?: boolean; } -export interface SortOptions { - mode?: 'min' | 'max' | 'sum' | 'avg' | 'median'; - type?: 'double' | 'long' | 'date' | 'date_nanos'; - nested?: object; - unmapped_type?: string; - distance_type?: 'arc' | 'plane'; - unit?: string; - ignore_unmapped?: boolean; - _script?: object; -} - -export interface Request { - docvalue_fields: string[]; - _source: unknown; - query: unknown; - script_fields: unknown; - sort: unknown; - stored_fields: string[]; -} - -export interface ResponseWithShardFailure { - _shards: { - failed: number; - failures: ShardFailure[]; - skipped: number; - successful: number; - total: number; - }; -} - -export interface ShardFailure { - index: string; - node: string; - reason: { - caused_by: { - reason: string; - type: string; - }; - reason: string; - lang?: estypes.ScriptLanguage; - script?: string; - script_stack?: string[]; - type: string; - }; - shard: number; -} - export function isSerializedSearchSource( maybeSerializedSearchSource: unknown ): maybeSerializedSearchSource is SerializedSearchSourceFields { diff --git a/src/plugins/discover/public/application/context/utils/fetch_hits_in_interval.ts b/src/plugins/discover/public/application/context/utils/fetch_hits_in_interval.ts index d9a06e08fbada..6f070b7335030 100644 --- a/src/plugins/discover/public/application/context/utils/fetch_hits_in_interval.ts +++ b/src/plugins/discover/public/application/context/utils/fetch_hits_in_interval.ts @@ -5,9 +5,9 @@ * in compliance with, at your election, the Elastic License 2.0 or the Server * Side Public License, v 1. */ +import { estypes } from '@elastic/elasticsearch'; import { lastValueFrom } from 'rxjs'; import { ISearchSource, EsQuerySortValue, SortDirection } from '@kbn/data-plugin/public'; -import { EsQuerySearchAfter } from '@kbn/data-plugin/common'; import { buildDataTableRecord } from '@kbn/discover-utils'; import type { DataTableRecord } from '@kbn/discover-utils/types'; import { @@ -39,7 +39,7 @@ export async function fetchHitsInInterval( sort: [EsQuerySortValue, EsQuerySortValue], sortDir: SortDirection, interval: IntervalValue[], - searchAfter: EsQuerySearchAfter, + searchAfter: estypes.SortResults, maxCount: number, nanosValue: string, anchorId: string, diff --git a/src/plugins/discover/public/application/context/utils/get_es_query_search_after.ts b/src/plugins/discover/public/application/context/utils/get_es_query_search_after.ts index 18792cb6a7ff8..c6bab71609e65 100644 --- a/src/plugins/discover/public/application/context/utils/get_es_query_search_after.ts +++ b/src/plugins/discover/public/application/context/utils/get_es_query_search_after.ts @@ -5,7 +5,7 @@ * in compliance with, at your election, the Elastic License 2.0 or the Server * Side Public License, v 1. */ -import type { EsQuerySearchAfter } from '@kbn/data-plugin/common'; +import { estypes } from '@elastic/elasticsearch'; import type { DataTableRecord } from '@kbn/discover-utils/types'; import { SurrDocType } from '../services/context'; @@ -19,7 +19,7 @@ export function getEsQuerySearchAfter( type: SurrDocType, rows: DataTableRecord[], anchor: DataTableRecord -): EsQuerySearchAfter { +): estypes.SortResults { if (rows.length) { // already surrounding docs -> first or last record is used const afterTimeRecIdx = type === SurrDocType.SUCCESSORS && rows.length ? rows.length - 1 : 0;