/** * Bulk indexing types for high-throughput document ingestion */ /** * Bulk operation types */ export type BulkOperationType = 'index' | 'create' | 'update' | 'delete'; /** * Bulk operation */ export interface BulkOperation { /** Operation type */ type: BulkOperationType; /** Target index */ index: string; /** Document ID */ id?: string; /** Document to index/update */ document?: T; /** Partial document for update */ partialDocument?: Partial; /** If_seq_no for optimistic concurrency */ ifSeqNo?: number; /** If_primary_term for optimistic concurrency */ ifPrimaryTerm?: number; /** Routing value */ routing?: string; /** Pipeline to execute */ pipeline?: string; /** Retry on conflict (for updates) */ retryOnConflict?: number; } /** * Bulk operation result */ export interface BulkOperationResult { /** Whether operation succeeded */ success: boolean; /** Operation type */ type: BulkOperationType; /** Index name */ index: string; /** Document ID */ id?: string; /** Error if operation failed */ error?: { type: string; reason: string; causedBy?: string; }; /** HTTP status code */ status?: number; /** Sequence number (for successful operations) */ seqNo?: number; /** Primary term (for successful operations) */ primaryTerm?: number; } /** * Bulk batch result */ export interface BulkBatchResult { /** Number of successful operations */ successful: number; /** Number of failed operations */ failed: number; /** Total operations in batch */ total: number; /** Time taken in milliseconds */ durationMs: number; /** Individual operation results */ results: BulkOperationResult[]; /** Whether batch had errors */ hasErrors: boolean; } /** * Progress callback */ export type BulkProgressCallback = (progress: BulkProgress) => void; /** * Bulk progress information */ export interface BulkProgress { /** Total operations submitted */ totalSubmitted: number; /** Total operations processed */ totalProcessed: number; /** Total successful operations */ totalSuccessful: number; /** Total failed operations */ totalFailed: number; /** Current queue size */ queueSize: number; /** Operations per second */ operationsPerSecond: number; /** Average batch duration */ avgBatchDurationMs: number; /** Estimated time remaining (ms) */ estimatedTimeRemainingMs?: number; } /** * Adaptive batching strategy */ export type BatchingStrategy = 'fixed' | 'adaptive' | 'size-based'; /** * Bulk indexer configuration */ export interface BulkIndexerConfig { /** Batching strategy */ batchingStrategy?: BatchingStrategy; /** Fixed batch size (for fixed strategy) */ batchSize?: number; /** Maximum batch size (for adaptive strategy) */ maxBatchSize?: number; /** Minimum batch size (for adaptive strategy) */ minBatchSize?: number; /** Target batch size in bytes (for size-based strategy) */ targetBatchBytes?: number; /** Flush interval in milliseconds */ flushIntervalMs?: number; /** Number of parallel workers */ workers?: number; /** Maximum queue size before backpressure */ maxQueueSize?: number; /** Maximum retries for failed operations */ maxRetries?: number; /** Retry delay in milliseconds */ retryDelayMs?: number; /** Enable dead-letter queue */ enableDeadLetterQueue?: boolean; /** Dead-letter queue index pattern */ deadLetterIndex?: string; /** Progress callback */ onProgress?: BulkProgressCallback; /** Callback for successful batch */ onBatchSuccess?: (result: BulkBatchResult) => void; /** Callback for failed batch */ onBatchError?: (error: Error, operations: BulkOperation[]) => void; /** Refresh policy */ refresh?: boolean | 'wait_for'; /** Default pipeline */ pipeline?: string; /** Default routing */ routing?: string; } /** * Bulk indexer statistics */ export interface BulkIndexerStats { /** Total operations submitted */ totalSubmitted: number; /** Total operations processed */ totalProcessed: number; /** Total successful operations */ totalSuccessful: number; /** Total failed operations */ totalFailed: number; /** Total operations in dead-letter queue */ totalDeadLettered: number; /** Total batches executed */ totalBatches: number; /** Total batches failed */ totalBatchesFailed: number; /** Current queue size */ queueSize: number; /** Operations per second (current) */ currentOpsPerSecond: number; /** Average operations per second */ avgOpsPerSecond: number; /** Average batch size */ avgBatchSize: number; /** Average batch duration */ avgBatchDurationMs: number; /** Started at */ startedAt?: Date; /** Last batch at */ lastBatchAt?: Date; /** Active workers */ activeWorkers: number; } /** * Backpressure state */ export interface BackpressureState { /** Whether backpressure is active */ active: boolean; /** Queue utilization percentage */ queueUtilization: number; /** Recommended wait time in milliseconds */ recommendedWaitMs: number; }