feathers-elasticsearch

A Feathers database adapter for Elasticsearch with full Feathers v5 (Dove) support, built-in security controls, and performance optimizations.
Features
- ✅ Feathers v5 (Dove) - Full compatibility with the latest Feathers
- 🔒 Security-First - Built-in protection against DoS attacks and unauthorized access
- ⚡ Performance - Query caching, lean mode, and complexity budgeting
- 🔍 Rich Queries - Full support for Elasticsearch-specific query operators
- 👨👩👧👦 Parent-Child - Support for parent-child relationships
- 📊 Bulk Operations - Efficient bulk create, patch, and remove
Installation
npm install feathers-elasticsearch @elastic/elasticsearch --save
Requirements:
- Feathers v5+
- Elasticsearch 8.x or 9.x (5.x, 6.x, 7.x also supported)
- Node.js 20+
Quick Start
import { feathers } '@feathersjs/feathers';
import express from '@feathersjs/express';
import { Client } from '@elastic/elasticsearch';
import service from 'feathers-elasticsearch';
const app = express(feathers());
const esClient = new Client({ node: 'http://localhost:9200' });
app.use('/messages', service({
Model: esClient,
elasticsearch: {
index: 'messages',
type: '_doc'
},
paginate: {
default: 10,
max: 50
}
}));
app.service('messages').create({
text: 'Hello Feathers!'
});
That's it! You now have a fully functional Feathers service with CRUD operations.
📚 Documentation
Getting Started
Configuration & Usage
Advanced Topics
Project Information
🚨 What's New in v4.0
Version 4.0.0 introduces breaking changes with a focus on security and performance.
Key Changes
1. Raw Method Access Disabled by Default
For security, the raw() method now requires explicit whitelisting:
await service.raw('indices.delete', { index: 'test' });
app.use('/messages', service({
Model: esClient,
elasticsearch: { index: 'messages', type: '_doc' },
security: {
allowedRawMethods: ['search', 'count']
}
}));
await service.raw('search', { query: {...} });
await service.raw('indices.delete', {...});
2. New Security Limits
Default limits protect against DoS attacks:
security: {
maxQueryDepth: 50,
maxBulkOperations: 10000,
maxArraySize: 10000,
}
3. Performance Improvements
- Content-based query caching (50-90% hit rate vs 5-10%)
- Lean mode for bulk operations (60% faster)
- Configurable refresh strategies
See the Migration Guide for complete upgrade instructions.
Example Usage
Basic CRUD
const message = await service.create({
text: 'Hello World',
user: 'Alice'
});
const results = await service.find({
query: {
user: 'Alice',
$sort: { createdAt: -1 },
$limit: 10
}
});
const message = await service.get(messageId);
await service.patch(messageId, {
text: 'Updated text'
});
await service.remove(messageId);
Elasticsearch-Specific Queries
const results = await service.find({
query: {
content: { $match: 'elasticsearch' }
}
});
const users = await service.find({
query: {
email: { $wildcard: '*@example.com' }
}
});
const articles = await service.find({
query: {
$sqs: {
$fields: ['title^5', 'content'],
$query: '+javascript +tutorial'
}
}
});
See Querying for all query operators and examples.
Performance Optimization
await service.create(largeDataset, {
lean: true,
refresh: false
});
await service.create(data, {
refresh: 'wait_for'
});
See Performance Features for optimization techniques.
Compatibility
Tested on:
- Elasticsearch 5.0, 5.6, 6.6, 6.7, 6.8, 7.0, 7.1, 8.x, 9.x
- Feathers v5 (Dove)
- Node.js 18+
Note: Support for Elasticsearch 2.4 was dropped in v3.0. Use feathers-elasticsearch v2.x for Elasticsearch 2.4.
Security
This package includes security features to protect against common vulnerabilities:
- Query depth limiting - Prevent stack overflow from deeply nested queries
- Bulk operation limits - Prevent memory exhaustion
- Raw method whitelisting - Control access to Elasticsearch API
- Input sanitization - Protect against prototype pollution
- Configurable limits - Adjust based on your needs
See Security for complete security documentation.
Contributing
We welcome contributions! Please see Contributing for guidelines.
Quick Start:
git clone https://github.com/feathersjs/feathers-elasticsearch.git
cd feathers-elasticsearch
npm install
ES_VERSION=8.11.0 npm test
ES_VERSION=8.11.0 npm run coverage
License
Copyright (c) 2025
Licensed under the MIT license.