import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey' ; import { SearchListItemArraySchema , Type } from '@kbn/securitysolution-io-ts-list-types' ; import { SearchEsListItemSchema } from '../../schemas/elastic_response' ; import { transformElasticHitsToListItem } from './transform_elastic_to_list_item' ; export interface TransformElasticMSearchToListItemOptions { response : estypes . SearchResponse < SearchEsListItemSchema > ; type : Type ; value : unknown [ ] ; } param response param type param value export const transformElasticNamedSearchToListItem = ( { response , type , value , } ) : SearchListItemArraySchema => { return value . map ( ( singleValue , index ) => { const matchingHits = response . hits . hits . filter ( ( hit ) => { if ( hit . matched_queries != null ) { return hit . matched_queries . some ( ( matchedQuery ) => { const [ matchedQueryIndex ] = matchedQuery . split ( '.' ) ; return matchedQueryIndex === `${ index }` ; } ) ; } else { return false ; } } ) ; const items = transformElasticHitsToListItem ( { hits : matchingHits , type } ) ; return { items , value : singleValue , } ; } ) ; } ;