export type RequestEncoding = 'base64' | 'Empty'; export type SearchEventContext = {alert_key?: (string | null) | undefined, alert_name?: (string | null) | undefined, dashboard_id?: (string | null) | undefined, dashboard_name?: (string | null) | undefined, derived_stream_key?: (string | null) | undefined, folder_id?: (string | null) | undefined, folder_name?: (string | null) | undefined, panel_id?: (string | null) | undefined, public_dashboard_link_id?: (string | null) | undefined, range_key?: (string | null) | undefined, report_id?: (string | null) | undefined}; export type SearchEventType = 'ui' | 'dashboards' | 'reports' | 'alerts' | 'values' | 'other' | 'rum' | 'derivedstream' | 'searchjob' | 'download' | 'insights' | 'public_dashboard'; export type SqlQuery = {end_time?: (number | null) | undefined, is_old_format?: boolean | undefined, query_fn?: (string | null) | undefined, sql: string, start_time?: (number | null) | undefined}; export type CreateApiApiOrgIdSearchMultiStreamArgs = {org_id: string, body: {clusters?: Array | undefined, encoding?: RequestEncoding | undefined, end_time: number, from?: number | undefined, index_type?: string | undefined, per_query_response?: boolean | undefined, query_fn?: (string | null) | undefined, quick_mode?: boolean | undefined, regions?: Array | undefined, search_event_context?: (SearchEventContext | null) | undefined, search_type?: (SearchEventType | null) | undefined, size?: number | undefined, skip_wal?: boolean | undefined, sort_by?: (string | null) | undefined, sql?: Array | undefined, start_time: number, timeout?: number | undefined, track_total_hits?: boolean | undefined, use_index?: boolean | undefined, uses_zo_fn?: boolean | undefined}}; export type CreateApiApiOrgIdSearchMultiStreamOptions = {baseUrl: string, Authorization?: string | undefined, fetch?: typeof fetch | undefined}; /** * Stream search results across multiple queries * * POST /api/{org_id}/_search_multi_stream */ export const createApiApiOrgIdSearchMultiStream = async (args: CreateApiApiOrgIdSearchMultiStreamArgs, options: CreateApiApiOrgIdSearchMultiStreamOptions) => { const {baseUrl, fetch: fetchFn = fetch, Authorization} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "text/event-stream") if (Authorization !== undefined) headers.set("Authorization", Authorization) const url = `${baseUrl.replace(/\/+$/, '')}/api/${encodeURIComponent(String(args.org_id))}/_search_multi_stream${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return res.text() };