/** * Schema Management Types * * Index mapping management, templates, and migrations */ /** * Elasticsearch field types */ export type FieldType = | 'text' | 'keyword' | 'long' | 'integer' | 'short' | 'byte' | 'double' | 'float' | 'half_float' | 'scaled_float' | 'date' | 'date_nanos' | 'boolean' | 'binary' | 'integer_range' | 'float_range' | 'long_range' | 'double_range' | 'date_range' | 'ip_range' | 'object' | 'nested' | 'geo_point' | 'geo_shape' | 'completion' | 'search_as_you_type' | 'token_count' | 'percolator' | 'join' | 'rank_feature' | 'rank_features' | 'dense_vector' | 'sparse_vector' | 'flattened' | 'shape' | 'histogram' | 'ip' | 'alias'; /** * Field definition */ export interface FieldDefinition { /** Field type */ type: FieldType; /** Index this field */ index?: boolean; /** Store this field */ store?: boolean; /** Enable doc values */ doc_values?: boolean; /** Analyzer for text fields */ analyzer?: string; /** Search analyzer */ search_analyzer?: string; /** Normalizer for keyword fields */ normalizer?: string; /** Boost factor */ boost?: number; /** Coerce values */ coerce?: boolean; /** Copy to other fields */ copy_to?: string | string[]; /** Enable norms */ norms?: boolean; /** Null value replacement */ null_value?: unknown; /** Ignore values above this length */ ignore_above?: number; /** Date format */ format?: string; /** Scaling factor for scaled_float */ scaling_factor?: number; /** Nested properties */ properties?: Record; /** Enable eager global ordinals */ eager_global_ordinals?: boolean; /** Similarity algorithm */ similarity?: string; /** Term vector */ term_vector?: 'no' | 'yes' | 'with_positions' | 'with_offsets' | 'with_positions_offsets'; /** Dimensions for dense_vector */ dims?: number; /** Additional properties */ [key: string]: unknown; } /** * Index settings */ export interface IndexSettings { /** Number of primary shards */ number_of_shards?: number; /** Number of replica shards */ number_of_replicas?: number; /** Refresh interval */ refresh_interval?: string; /** Maximum result window */ max_result_window?: number; /** Maximum inner result window */ max_inner_result_window?: number; /** Maximum rescore window */ max_rescore_window?: number; /** Maximum docvalue fields search */ max_docvalue_fields_search?: number; /** Maximum script fields */ max_script_fields?: number; /** Maximum regex length */ max_regex_length?: number; /** Codec */ codec?: string; /** Routing partition size */ routing_partition_size?: number; /** Soft deletes retention period */ soft_deletes?: { retention_lease?: { period?: string; }; }; /** Analysis settings */ analysis?: { analyzer?: Record; tokenizer?: Record; filter?: Record; char_filter?: Record; normalizer?: Record; }; /** Additional settings */ [key: string]: unknown; } /** * Index mapping */ export interface IndexMapping { /** Dynamic mapping behavior */ dynamic?: boolean | 'strict' | 'runtime'; /** Date detection */ date_detection?: boolean; /** Dynamic date formats */ dynamic_date_formats?: string[]; /** Numeric detection */ numeric_detection?: boolean; /** Field properties */ properties: Record; /** Runtime fields */ runtime?: Record; /** Meta fields */ _source?: { enabled?: boolean; includes?: string[]; excludes?: string[]; }; _routing?: { required?: boolean; }; _meta?: Record; } /** * Index schema definition */ export interface IndexSchema { /** Index name or pattern */ name: string; /** Schema version */ version: number; /** Index settings */ settings?: IndexSettings; /** Index mapping */ mappings: IndexMapping; /** Index aliases */ aliases?: Record; /** Lifecycle policy */ lifecycle?: { name: string; rollover_alias?: string; }; /** Schema metadata */ metadata?: { description?: string; owner?: string; created?: Date; updated?: Date; tags?: string[]; }; } /** * Schema migration */ export interface SchemaMigration { /** Migration version (must be unique) */ version: number; /** Migration name */ name: string; /** Migration description */ description?: string; /** Migration type */ type: 'create' | 'update' | 'delete' | 'reindex' | 'alias'; /** Target index */ index: string; /** Changes to apply */ changes: { /** Settings changes */ settings?: Partial; /** Mapping changes (new or modified fields) */ mappings?: { properties?: Record; dynamic?: boolean | 'strict' | 'runtime'; }; /** Alias changes */ aliases?: { add?: Record; remove?: string[]; }; /** Reindex configuration */ reindex?: { source: string; dest: string; script?: string; }; }; /** Rollback changes */ rollback?: { settings?: Partial; mappings?: { properties?: Record; }; }; /** Migration metadata */ metadata?: { author?: string; created?: Date; ticket?: string; }; } /** * Migration status */ export type MigrationStatus = 'pending' | 'running' | 'completed' | 'failed' | 'rolled_back'; /** * Migration history entry */ export interface MigrationHistoryEntry { /** Migration version */ version: number; /** Migration name */ name: string; /** Migration status */ status: MigrationStatus; /** Started at */ startedAt: Date; /** Completed at */ completedAt?: Date; /** Duration in milliseconds */ duration?: number; /** Error if failed */ error?: string; /** Checksum of migration */ checksum?: string; } /** * Schema manager configuration */ export interface SchemaManagerConfig { /** Index for storing migration history */ historyIndex?: string; /** Enable dry run mode */ dryRun?: boolean; /** Enable strict mode (fail on warnings) */ strict?: boolean; /** Timeout for operations */ timeout?: number; /** Enable logging */ enableLogging?: boolean; /** Enable metrics */ enableMetrics?: boolean; /** Validate schemas before applying */ validateBeforeApply?: boolean; } /** * Schema validation result */ export interface SchemaValidationResult { /** Whether schema is valid */ valid: boolean; /** Validation errors */ errors: Array<{ field: string; message: string; severity: 'error' | 'warning'; }>; /** Validation warnings */ warnings: Array<{ field: string; message: string; }>; } /** * Schema diff result */ export interface SchemaDiff { /** Whether schemas are identical */ identical: boolean; /** Added fields */ added: string[]; /** Removed fields */ removed: string[]; /** Modified fields */ modified: Array<{ field: string; from: FieldDefinition; to: FieldDefinition; }>; /** Settings changes */ settingsChanged: boolean; /** Aliases changes */ aliasesChanged: boolean; /** Breaking changes */ breakingChanges: string[]; } /** * Template definition */ export interface IndexTemplate { /** Template name */ name: string; /** Index patterns */ index_patterns: string[]; /** Template priority */ priority?: number; /** Template version */ version?: number; /** Composed of component templates */ composed_of?: string[]; /** Template settings */ template?: { settings?: IndexSettings; mappings?: IndexMapping; aliases?: Record; }; /** Data stream settings */ data_stream?: { hidden?: boolean; allow_custom_routing?: boolean; }; /** Template metadata */ _meta?: Record; } /** * Component template */ export interface ComponentTemplate { /** Template name */ name: string; /** Template content */ template: { settings?: IndexSettings; mappings?: IndexMapping; aliases?: Record; }; /** Template version */ version?: number; /** Template metadata */ _meta?: Record; } /** * Schema manager statistics */ export interface SchemaManagerStats { /** Total migrations applied */ totalMigrations: number; /** Successful migrations */ successfulMigrations: number; /** Failed migrations */ failedMigrations: number; /** Rolled back migrations */ rolledBackMigrations: number; /** Total indices managed */ totalIndices: number; /** Total templates managed */ totalTemplates: number; /** Last migration time */ lastMigrationTime?: Date; /** Average migration duration */ avgMigrationDuration: number; }