From 0db58e435b640e63795ed92f3f83b649eee8847e Mon Sep 17 00:00:00 2001 From: Mikhail Shustov Date: Thu, 29 Jul 2021 20:14:37 +0300 Subject: [PATCH] [Maps] [Infra] do not import types from the legacy elasticsearch package (#107118) * remove elasticsearch import from infra * remove elasticsearch import from maps --- .../server/lib/adapters/framework/adapter_types.ts | 7 ++++--- .../sources/es_geo_grid_source/es_geo_grid_source.tsx | 10 ++++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/x-pack/plugins/infra/server/lib/adapters/framework/adapter_types.ts b/x-pack/plugins/infra/server/lib/adapters/framework/adapter_types.ts index 0ec071b97d7cf6..f33bcd2fcab0ca 100644 --- a/x-pack/plugins/infra/server/lib/adapters/framework/adapter_types.ts +++ b/x-pack/plugins/infra/server/lib/adapters/framework/adapter_types.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { GenericParams, SearchResponse } from 'elasticsearch'; +import type { estypes } from '@elastic/elasticsearch'; import { Lifecycle } from '@hapi/hapi'; import { UsageCollectionSetup } from 'src/plugins/usage_collection/server'; import { JsonArray, JsonValue } from '@kbn/common-utils'; @@ -38,7 +38,7 @@ export interface InfraServerPluginStartDeps { data: DataPluginStart; } -export interface CallWithRequestParams extends GenericParams { +export interface CallWithRequestParams extends estypes.RequestBase { max_concurrent_shard_requests?: number; name?: string; index?: string | string[]; @@ -50,6 +50,7 @@ export interface CallWithRequestParams extends GenericParams { path?: string; query?: string | object; track_total_hits?: boolean | number; + body?: any; } export type InfraResponse = Lifecycle.ReturnValue; @@ -117,7 +118,7 @@ export interface InfraDatabaseGetIndicesResponse { }; } -export type SearchHit = SearchResponse['hits']['hits'][0]; +export type SearchHit = estypes.SearchHit; export interface SortedSearchHit extends SearchHit { sort: any[]; diff --git a/x-pack/plugins/maps/public/classes/sources/es_geo_grid_source/es_geo_grid_source.tsx b/x-pack/plugins/maps/public/classes/sources/es_geo_grid_source/es_geo_grid_source.tsx index 69ec0740948fcb..f0cec4abf0b14d 100644 --- a/x-pack/plugins/maps/public/classes/sources/es_geo_grid_source/es_geo_grid_source.tsx +++ b/x-pack/plugins/maps/public/classes/sources/es_geo_grid_source/es_geo_grid_source.tsx @@ -10,7 +10,7 @@ import React, { ReactElement } from 'react'; import { i18n } from '@kbn/i18n'; import rison from 'rison-node'; import { Feature } from 'geojson'; -import { SearchResponse } from 'elasticsearch'; +import type { estypes } from '@elastic/elasticsearch'; import { convertCompositeRespToGeoJson, convertRegularRespToGeoJson, @@ -274,7 +274,7 @@ export class ESGeoGridSource extends AbstractESAggSource implements ITiledSingle const requestId: string = afterKey ? `${this.getId()} afterKey ${afterKey.geoSplit}` : this.getId(); - const esResponse: SearchResponse = await this._runEsQuery({ + const esResponse: estypes.SearchResponse = await this._runEsQuery({ requestId, requestName: `${layerName} (${requestCount})`, searchSource, @@ -291,8 +291,10 @@ export class ESGeoGridSource extends AbstractESAggSource implements ITiledSingle features.push(...convertCompositeRespToGeoJson(esResponse, this._descriptor.requestType)); - afterKey = esResponse.aggregations.compositeSplit.after_key; - if (esResponse.aggregations.compositeSplit.buckets.length < gridsPerRequest) { + const aggr = esResponse.aggregations + ?.compositeSplit as estypes.AggregationsCompositeBucketAggregate; + afterKey = aggr.after_key; + if (aggr.buckets.length < gridsPerRequest) { // Finished because request did not get full resultset back break; }