A TypeScript library (v0.58.0) that syncs MongoDB collections to Elasticsearch using change streams and optional schema conversion. It supports initial bulk scans, real-time change stream processing, schema change detection, and automatic mapping generation from MongoDB JSON schemas with Elasticsearch-specific overrides (e.g., geo_point, nested types, copy_to). Active development with monthly releases. Key differentiators: provides both a sync engine and standalone schema conversion utilities, handles change stream lifecycle (start/stop on schema change), and supports Redis-backed resume tokens. Requires Node >=16, MongoDB >=6.8, Elasticsearch >=8.14, and ioredis >=5.4.
npm install mongo2elasticNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows a full sync setup: MongoDB connection, Elasticsearch client, Redis for resume tokens, optional field omission, index creation with ignore_malformed, mapping from schema, change stream processing, schema change detection, and initial scan.
Ensure Node.js >=16, MongoDB driver >=6.8, Elasticsearch client >=8.14, ioredis >=5.4.
Use ES module syntax (import/export) and set 'type: module' in package.json, or use dynamic import() in a CJS context.
Provide a valid ioredis instance. If not needed, check docs for alternative initialization.
Listen for 'schemaChange' and re-run schema detection and mapping creation as needed.
Either delete the existing index first or handle the error gracefully.
Use import { initSync } from 'mongo2elastic' or set type: module in package.json.Instantiate Redis via new Redis() before passing to initSync.
Connect to a MongoDB replica set or use a service like MongoDB Atlas.
Check ELASTIC_NODE, ELASTIC_USERNAME, and ELASTIC_PASSWORD environment variables. Ensure Elasticsearch is running.