import { Client } from '@elastic/elasticsearch' ; import type { ClientOptions } from '@elastic/elasticsearch/lib/client' ; import { ESSearchResponse , ESSearchRequest , } from '../../../../../src/core/types/elasticsearch' ; export type ESClient = ReturnType < typeof getEsClient > ; export function getEsClient ( { node , auth , } ) { const client = new Client ( { node , tls : { rejectUnauthorized : false , } , requestTimeout : 120000 , auth , } ) ; const originalSearch = client . search . bind ( client ) ; async function search < TDocument = unknown , TSearchRequest extends ESSearchRequest = ESSearchRequest > ( request ) { const response = await originalSearch ( request ) ; return { ... response , body : response as unknown as ESSearchResponse < TDocument , TSearchRequest > , } ; } client . search = search ; return client as unknown as Omit < Client , 'search' > & { search : typeof search ; } ; }