import { Transport , TransportRequestOptions , TransportRequestOptionsWithMeta , TransportRequestOptionsWithOutMeta , TransportResult } from '@elastic/transport' ; import * as T from '../types' ; import * as TB from '../typesWithBodyKey' ; interface That { transport : Transport ; } export default async function SearchApi < TDocument = unknown , TAggregations = Record < T . AggregateName , T . AggregationsAggregate > > ( this , params ? , options ? ) ; export default async function SearchApi < TDocument = unknown , TAggregations = Record < T . AggregateName , T . AggregationsAggregate > > ( this , params ? , options ? ) ; export default async function SearchApi < TDocument = unknown , TAggregations = Record < T . AggregateName , T . AggregationsAggregate > > ( this , params ? , options ? ) ; export default async function SearchApi < TDocument = unknown , TAggregations = Record < T . AggregateName , T . AggregationsAggregate > > ( this , params ? , options ? ) { const acceptedPath = [ 'index' ] ; const acceptedBody = [ 'aggregations' , 'aggs' , 'collapse' , 'explain' , 'from' , 'highlight' , 'track_total_hits' , 'indices_boost' , 'docvalue_fields' , 'min_score' , 'post_filter' , 'profile' , 'query' , 'rescore' , 'script_fields' , 'search_after' , 'size' , 'slice' , 'sort' , '_source' , 'fields' , 'suggest' , 'terminate_after' , 'timeout' , 'track_scores' , 'version' , 'seq_no_primary_term' , 'stored_fields' , 'pit' , 'runtime_mappings' , 'stats' ] ; const querystring = { } ; const userBody = params ?. body ; let body ; if ( typeof userBody === 'string' ) { body = userBody ; } else { body = userBody != null ? { ... userBody } : undefined ; } params = params ?? { } ; for ( const key in params ) { if ( acceptedBody . includes ( key ) ) { body = body ?? { } ; if ( key === 'sort' && typeof params [ key ] === 'string' && params [ key ] . includes ( ':' ) ) { querystring [ key ] = params [ key ] ; } else { body [ key ] = params [ key ] ; } } else if ( acceptedPath . includes ( key ) ) { continue ; } else if ( key !== 'body' ) { querystring [ key ] = params [ key ] ; } } let method = '' ; let path = '' ; if ( params . index != null ) { method = body != null ? 'POST' : 'GET' ; path = `/${ encodeURIComponent ( params . index . toString ( ) ) }/_search` ; } else { method = body != null ? 'POST' : 'GET' ; path = '/_search' ; } return await this . transport . request ( { path , method , querystring , body } , options ) ; }