Registry / database / elasticsearch-orm

elasticsearch-orm

JSON →
library1.0.29jsnpmunverified

An ORM-like query API for Elasticsearch that simplifies index management, document CRUD, and complex query building. Current stable version is 1.0.29. Provides a fluent query builder with support for term, match, must/should/not conditions, aggregations, pagination, and more. Key differentiators include minimal configuration, built-in index synchronization, and support for geo points. The package appears to be in an early stage with limited community adoption and maintenance.

npm install elasticsearch-orm
INSTALL
IMPORT
SIG · ELASTICSEARCH-ORM
E
elasticsearch-orm
databasejavascriptv1.0.29
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

elasticsearch-orm
const orm = require('elasticsearch-orm');
import orm from 'elasticsearch-orm';
Package uses CommonJS exports; ES module import may not work without configuration.
Condition
const Condition = require('elasticsearch-orm').Condition;
import { Condition } from 'elasticsearch-orm';
Condition is exported as a property of the module.
instance.on('connected')
const instance = orm({...}); instance.on('connected', callback);
instance.on('connect', callback);
Event name is 'connected' not 'connect'.

Connects to Elasticsearch, registers an index with mappings and settings, synchronizes, creates a document, and retrieves it.

const orm = require('elasticsearch-orm'); const instance = orm({ 'domain': process.env.ES_HOST ?? '127.0.0.1', 'port': parseInt(process.env.ES_PORT ?? '9200') }); instance.on('connected', () => { console.log('Connected to Elasticsearch'); const demoIndex = instance.register('demoIndex', { 'index': 'demoindex', 'type': 'demotype' }, { 'title': { 'type': 'text' }, 'age': { 'type': 'integer' }, 'location': { 'type': 'geo_point' } }, { 'number_of_shards': 2, 'number_of_replicas': 4 }); demoIndex.sync().then(() => { console.log('Index synchronized'); return demoIndex.create({ 'title': 'Test', 'age': 25 }); }).then(id => { console.log('Created document with ID:', id); return demoIndex.get(id); }).then(doc => { console.log('Retrieved document:', doc); }).catch(err => { console.error('Error:', err); }); }); instance.on('error', (e) => { console.log('Connection error:', e); });
Debug
Known issues
gotchaEvent name for connection success is 'connected' (past tense) not 'connect'.
fix
Use instance.on('connected', ...) instead of instance.on('connect', ...).
affects: >=1.0.0
gotchaThe get method throws an error if document ID does not exist; it does not return null.
fix
Use try/catch when calling get, or check existence via exists() before get().
affects: >=1.0.0
deprecatedThe package relies on the deprecated elasticsearch npm package (v16.x) which is in maintenance mode.
fix
Consider migrating to @elastic/elasticsearch (v7+) and using a different ORM that supports the new client.
affects: >=1.0.0
gotchaQuery conditions (term, match, etc.) are chainable but must end with .query() to execute.
fix
Always call .query() at the end of a query chain, e.g., instance.term('age',12).query()
affects: >=1.0.0
gotchaThe create method accepts optional parameters (id, routing, options) but order matters: create(body, id, routing, options).
fix
Follow the exact parameter order: body, id (optional), routing (optional), options (optional).
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: orm is not a function
Incorrect import method (e.g., using ES module import on a CommonJS module without default export).
fix
Use require('elasticsearch-orm') instead of import.
Error: document not found
Calling get() with a non-existent document ID.
fix
Use exists() method first, or wrap get() in a try/catch.
TypeError: Condition is not a constructor
Incorrect import of Condition class (e.g., destructuring import).
fix
Use const Condition = require('elasticsearch-orm').Condition;
Upgrade
Version history
1.0.29latest on npm
Audit
Dependencies
elasticsearchrequiredUnderlying Elasticsearch client for Node.js
Agent activity
7 hits · last 30 days
node
6
Resources
elasticsearch-orm — npm install elasticsearch-orm · libregistry