This directory contains practical code examples demonstrating common use cases for node-es-transformer.
Before running any example, make sure you have:
- Elasticsearch running (default:
http://localhost:9200) - node-es-transformer installed:
npm install node-es-transformeroryarn add node-es-transformer
Then run any example:
node examples/basic-file-ingestion.jsDemonstrates the simplest use case: ingesting a JSON or CSV file into Elasticsearch with custom field mappings.
Key concepts:
- File-based ingestion
- Custom mappings
- Authentication configuration
Shows how to reindex data from one Elasticsearch index to another while transforming documents.
Key concepts:
- Index-to-index reindexing
- Transform functions
- Filtering with queries
- Computed fields
Demonstrates migrating data between Elasticsearch major versions (e.g., 8.x → 9.x).
Key concepts:
- Multi-version support
- Auto-detection vs manual version selection
- Pre-instantiated clients
Shows how to split one source document into multiple target documents (e.g., one tweet → multiple hashtag docs).
Key concepts:
- Returning arrays from transform
- Entity-centric indexing
- Conditional document creation
Demonstrates batch processing multiple files using wildcard patterns.
Key concepts:
- Wildcard file patterns
- Batch processing
- Adding file context to documents
Shows how to ingest data from Node.js streams (APIs, databases, custom sources).
Key concepts:
- Stream-based ingestion
- HTTP API streaming
- Database cursor streaming
Demonstrates TypeScript usage with full type safety and IntelliSense support.
Key concepts:
- Type definitions for all options
- Typed transform functions
- Type-safe document interfaces
Always use environment variables for credentials:
transformer({
targetClientConfig: {
node: 'https://elasticsearch.example.com:9200',
auth: {
apiKey: process.env.ES_API_KEY // Never hardcode
}
}
});Wrap transformer calls with try/catch or use .catch():
const pino = require('pino');
const logger = pino({ name: 'my-app', level: process.env.LOG_LEVEL || 'info' });
transformer({ /* options */ })
.then(() => logger.info('Success'))
.catch(err => logger.error({ err }, 'Transformer failed'));The library displays progress bars automatically. Set verbose: false to disable:
transformer({
fileName: 'large-file.json',
targetIndexName: 'my-index',
verbose: false // Disable progress output
});- Check the README for full API documentation
- Review the test files for more usage examples
- Open an issue on GitHub for questions