
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
elastickbird
Advanced tools
A high-level Elasticsearch driver for Node.js, inspired by Mongoose and Sequelize. Elastickbird provides an elegant, model-based solution to work with Elasticsearch, making it easy to define mappings, perform CRUD operations, and execute complex queries.
npm install elastickbird
import { ElasticsearchClient } from 'elastickbird';
// Configure the Elasticsearch client
ElasticsearchClient.configure({
node: 'http://localhost:9200',
auth: {
username: 'elastic',
password: 'password'
}
});
import { ElastickbirdModel } from 'elastickbird';
// Define your model
const User = new ElastickbirdModel({
alias: 'users',
primaryKeyAttribute: 'id',
mappings: {
properties: {
id: { type: 'keyword' },
name: { type: 'text' },
email: { type: 'keyword' },
age: { type: 'integer' },
createdAt: { type: 'date' }
}
},
settings: {
number_of_shards: 1,
number_of_replicas: 0
}
});
// Create the index
await User.createIndex();
// Index a document
const result = await User.indexDocument({
id: '1',
name: 'John Doe',
email: 'john@example.com',
age: 30,
createdAt: new Date()
});
// Get a document by ID
const user = await User.getDocument({ id: '1' });
// Update a document
await User.updateDocument({
id: '1',
name: 'John Smith',
age: 31
});
// Delete a document
await User.deleteDocument({ id: '1' });
// Create a query builder
const query = User.query();
// Build a complex query
query
.addTerm('status', 'active')
.should({ minimumShouldMatch: 1 })
.addMatch('name', 'john')
.addRange('age', { gte: 18, lte: 65 })
.setSize(10)
.addSort('createdAt', 'desc');
// Execute the search
const searchResults = await query.search()
console.log(searchResults.rows); // Array of matching documents
console.log(searchResults.count); // Total count
// Initialize bulk operation
const bulk = User.initBulk({ batchSize: 1000 });
// Add multiple operations
bulk.addIndexOperation({ id: '1', name: 'User 1', email: 'user1@example.com' });
bulk.addIndexOperation({ id: '2', name: 'User 2', email: 'user2@example.com' });
bulk.addUpdateOperation({ id: '1', name: 'Updated User 1' });
// Execute all operations
const bulkResult = await bulk.execute();
console.log(bulkResult.success); // true if all operations succeeded
const model = new ElastickbirdModel({
alias: 'orders',
routing: 'customerId', // Route documents by customer ID
mappings: {
properties: {
id: { type: 'keyword' },
customerId: { type: 'keyword' },
amount: { type: 'float' }
}
}
});
// The `customerId` will automatically be used for routing, determining in which shard the document will be located.
await User.createDocument({ id: '1', customerId: 'abc123' });
// Adding a filter by `customerId` will automatically add the routing to the search,
// causing Elasticsearch to search only in the relevant shard. This makes the query faster.
User.query().addTerm("customerId", 'abc123')
import { ElastickbirdFilterRules } from 'elastickbird';
const filterRules = new ElastickbirdFilterRules({
'active-users': (query) => {
query.addTerm('status', 'active');
},
'recent': (query) => {
query.addRange('createdAt', { gte: 'now-7d' });
}
});
const model = new ElastickbirdModel({
alias: 'users',
filterRules,
mappings: { /* ... */ }
});
// Use filter rules in queries
const query = model.query();
query.applyFilters('active-users,recent');
// Initialize bulk queue for auto-batching
const bulkQueue = User.initBulkQueue({ batchSize: 500 });
// Add operations in a loop
for (let i = 1; i <= 2000; i++) {
bulkQueue.addOperationsToQueue('index', [
{ id: String(i), name: `User ${i}` }
]);
// As you add operations, Elastickbird automatically batches and sends them to Elasticsearch for efficient processing.
}
// Wait for all operations to complete
const result = await bulkQueue.waitForCompletion();
The main class for defining and working with Elasticsearch indices.
interface ElastickBirdSchema {
alias: string; // Index alias name
mappings: Record<string, any>; // Elasticsearch mappings
primaryKeyAttribute?: string; // Primary key field (default: 'id')
primaryKeyAttributes?: string[]; // Multiple primary key fields
settings?: Record<string, any>; // Index settings
routing?: string; // Routing field
routingRules?: Record<string, (value: any) => string>;
filterRules?: ElastickbirdFilterRules;
sortRules?: Record<string, (query: any, order: string) => void>;
searchAfterDelimiter?: string; // Delimiter for search-after (default: '~')
}
createIndex(options?) - Create a new indexcreateIndexIfNotExists() - Create index if it doesn't existdeleteIndex() - Delete the current indextruncateIndex() - Delete and recreate the indexsyncMapping() - Update index mappingsindexDocument(payload, options?) - Index a documentcreateDocument(payload, options?) - Create a document (fails if exists)updateDocument(payload, options?) - Update a documentdeleteDocument(payload, options?) - Delete a documentsearch(request, options?) - Execute a search querydeleteByQuery(params) - Delete documents by queryupdateByQuery(params) - Update documents by querydocumentExists(payload) - Check if document existsgetDocument(payload) - Get document by payloadgetDocumentById(id) - Get document by IDquery() - Create a new query builderinitBulk(options?) - Initialize bulk operationsinitBulkQueue(options?) - Initialize auto-batching bulk queueFluent API for building Elasticsearch queries.
addTerm(field, value) - Add term queryaddTerms(field, values) - Add terms queryaddMatch(field, value) - Add match queryaddRange(field, query) - Add range queryaddExists(field) - Add exists queryaddQueryString(query, options?) - Add query stringaddCustomClause(clause) - Add custom query clausemust() - Must occurrence (AND)should(options?) - Should occurrence (OR)filter() - Filter occurrence (no scoring)mustNot() - Must not occurrence (NOT)setSize(size) - Set result sizesetFrom(from) - Set offset for paginationaddSort(field, order?) - Add sort clausesetSearchAfter(searchAfter) - Set search-after for paginationbuild() - Build the final query objectContributions are welcome! Please feel free to submit a Pull Request.
Apache-2.0
If you have any questions or need help, please open an issue on GitHub.
FAQs
elasticsearch object modeling for nodejs
The npm package elastickbird receives a total of 2 weekly downloads. As such, elastickbird popularity was classified as not popular.
We found that elastickbird demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.