zackiles / elasticsearch-odm Goto Github PK
View Code? Open in Web Editor NEWLike Mongoose but for Elasticsearch. Define models, preform CRUD operations, and build advanced search queries.
License: MIT License
Like Mongoose but for Elasticsearch. Define models, preform CRUD operations, and build advanced search queries.
License: MIT License
Seems to be fine, but should do a once over to compare changes in ElasticSearch JS client library for version 2.0+, and test for broken changes with elasticsearch-odm, prepare for upcoming changes in Elasticsearch core and other edge cases.
Elasticsearch-odm was built during 1.7.
With my limited knowledge,
There was an issue when I using elasticsearch-odm into sails framework.
Could you provide a example?
so, would u help me ?
THX !
Hi!
Is it possible to use "parent/child" relationships wiht elasticsearch-odm-5 ?
I see it in the TODO list.
Is it still on the TODO list or is the list just not updated? Thanks
I just trying out the example directly from README
var elasticsearch = require('elasticsearch-odm')
var Car = elasticsearch.model('Car')
var car = new Car({
type: 'Ford', color: 'Black'
})
elasticsearch.connect('my-index').then(function () {
// be sure to call connect before bootstrapping your app.
car.save().then(function (document) {
console.log(document)
})
}).catch(e => {
console.log('Error: ', e)
})
and that gives me this
Unhandled rejection Error: Bad Request
at respond (/Users/yeri/dev/chatio/node_modules/elasticsearch-odm/node_modules/elasticsearch/src/lib/transport.js:238:15)
at checkRespForFailure (/Users/yeri/dev/chatio/node_modules/elasticsearch-odm/node_modules/elasticsearch/src/lib/transport.js:201:7)
at HttpConnector.<anonymous> (/Users/yeri/dev/chatio/node_modules/elasticsearch-odm/node_modules/elasticsearch/src/lib/connectors/http.js:155:7)
at IncomingMessage.wrapper (/Users/yeri/dev/chatio/node_modules/elasticsearch-odm/node_modules/lodash/index.js:3095:19)
at emitNone (events.js:91:20)
at IncomingMessage.emit (events.js:185:7)
at endReadableNT (_stream_readable.js:974:12)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9)
I'm using node v.6.9.4 on mac
calls to .find() when used with pagination (page per_page options) that don't find anything returns an array, when it should be a PageResponse with an empty hits property.
I really wanted to work with ElasticSearch-ODM, however its having issues with basic find queries?
My code for connecting to Elastic Search:
//Connecting to ElasticSearch
var elasticSearch = require('elasticsearch-odm');
elasticSearch.connect({
host: 'http://localhost:9200/',
index: 'insightapp',
logging: false, // true by default when NODE_ENV=development
syncMapping: false, // see 'sync mapping' in Schemas documentation
});
Very basic Schema defined:
// Schema
var sampleSchema = new elasticSearch.Schema({
message: String
});
//Model Created
var sample = elasticSearch.model('sample', sampleSchema);
Querying the the message from the sample '_type'
//Querying Schema
sample.find({message:"value"}).then(function(results){
console.log(JSON.stringify(results));
});
This is the error I receive, for some reason it seems to be doing a match_all{}. Furthermore, it defines the _type value as 'samples' instead of 'sample'
[parsing_exception] no [query] registered for [filtered], with: {"line":1,"col":22} :: {"path":
"/insightapp/samples/_search","query":{"size":999999,"from":0},"body":"{\"query\":{\"filtered\":{\"query\":{\"match_all\":{}},\"filter\":{\"bool\":{\"must\":{\"term\":{\"message\":\"value\
"}}}}}}}","statusCode":400,"response":"{\"error\":{\"root_cause\":[{\"type\":\"parsing_exception\",\"reason\":\"no [query] registered for [filtered]\",\"line\":1,\"col\":22}],\"type\":\"pa
rsing_exception\",\"reason\":\"no [query] registered for [filtered]\",\"line\":1,\"col\":22},\"status\":400}"}
Here's the Basic JSON structure of my document in Kibana
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 1,
"hits": [
{
"_index": "insightapp",
"_type": "sample",
"_id": "AV88KaZScLtHquOiwSoM",
"_score": 1,
"_source": {
"message": "value"
}
}
]
}
}
Any help would be greatly appreciated. I would really like myself & my coworkers to work with this ODM library
Validator values on fields with types marked 'double' when that number doesn't have a decimal. E.g Numbers like '2' should pass validation without being '2.0'
Calls to connect should automatically create the index if it doesn't exist. In the rare case it doesn't, it automatically creates the index, but then hangs instead of resolving the promise. This requires restarting the application once more and then everything works like normal.
Hi
I'm currently working with the fork lakowalski/elasticsearch-odm and it seems that the two keywords : 'text' and 'keyword' that replace 'String' in Elasticsearch 5 don't exist in the odm.
Thank you.
How to execute Elastic range query?
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-range-query.html
To reproduce:
elasticsearch = require("elasticsearch-odm");
elasticsearch.connect("test-index");
Unhandled rejection TypeError: ConnectionError is not a constructor
at createIndex (/home/dan/Projects/kasra2/web-app/node_modules/elasticsearch-odm/index.js:84:44)
at /home/dan/Projects/kasra2/web-app/node_modules/elasticsearch-odm/index.js:62:14
at bound (domain.js:280:14)
at runBound (domain.js:293:12)
at tryCatcher (/home/dan/Projects/kasra2/web-app/node_modules/elasticsearch-odm/node_modules/bluebird/js/main/util.js:26:23)
at Promise._settlePromiseFromHandler (/home/dan/Projects/kasra2/web-app/node_modules/elasticsearch-odm/node_modules/bluebird/js/main/promise.js:503:31)
at Promise._settlePromiseAt (/home/dan/Projects/kasra2/web-app/node_modules/elasticsearch-odm/node_modules/bluebird/js/main/promise.js:577:18)
at Promise._settlePromises (/home/dan/Projects/kasra2/web-app/node_modules/elasticsearch-odm/node_modules/bluebird/js/main/promise.js:693:14)
at Async._drainQueue (/home/dan/Projects/kasra2/web-app/node_modules/elasticsearch-odm/node_modules/bluebird/js/main/async.js:123:16)
at Async._drainQueues (/home/dan/Projects/kasra2/web-app/node_modules/elasticsearch-odm/node_modules/bluebird/js/main/async.js:133:10)
at Immediate.Async.drainQueues [as _onImmediate] (/home/dan/Projects/kasra2/web-app/node_modules/elasticsearch-odm/node_modules/bluebird/js/main/async.js:15:14)
at tryOnImmediate (timers.js:543:15)
at processImmediate [as _immediateCallback] (timers.js:523:5)
Elasticsearch server info:
$ curl 'localhost:9200'
{
"name" : "Human Torch",
"cluster_name" : "elasticsearch",
"version" : {
"number" : "2.3.4",
"build_hash" : "e455fd0c13dceca8dbbdbb1665d068ae55dabe3f",
"build_timestamp" : "2016-06-30T11:24:31Z",
"build_snapshot" : false,
"lucene_version" : "5.5.0"
},
"tagline" : "You Know, for Search"
}
Checked on Node v6.3 and v4.3.
ConnectionError
from index.js, just after the requires, shows that it is undefinedThe issue is with a line of code in the Schema validation,
if(field){
if(fieldType.type.compare(field) === false){
errs.push(new ValidatorError(path, "Value '" + field + "' Not of type '" + fieldType.type.esType + '".'));
}
}else{
if(fieldType.options.required && !partial){
errs.push(new ValidatorError(path, 'Required field is missing.'));
}
}
Simply changing the field
to !_.isUndefined(field)
fixes this.
I'll do a PR for it.
Hi,
I'm currently trying to use elasticsearch-odm with elasticsearch 5.4.0 but the ODM doesn't seem compatible with this version. Do you plan on upgrading the ODM ?
thank you
The documentation says that the connect would create the index if it doesn't exists, but using it with elasticsearch-5.1.1 would return a 400 response on every call.
ElasticSearch version: 2.4.6
Npm package: [email protected]
import * as elasticsearch from "elasticsearch-odm";
elasticsearch.connect({
host: "http://localhost:9200",
index: "thing",
syncMapping: false
});
const searchSchema = new elasticsearch.Schema({
thingId: { type: String },
});
const model = elasticsearch.model("stuff", searchSchema);
const elasticSearchCRUD = async (thingId) => {
console.log("\nCreating thing with thingId: ", thingId);
await model.create({ thingId });
await new Promise(res => setTimeout(res, 1000));
let thing = await model.findOne({ thingId });
console.log("\nBefore update");
console.log(thing);
await new Promise(res => setTimeout(res, 1000));
await thing.update({field: "field"});
thing = await model.findOne({ thingId });
console.log("\nAfter update");
console.log(thing);
await new Promise(res => setTimeout(res, 1000));
await thing.remove();
thing = await model.findOne({ thingId });
console.log("\nAfter remove");
console.log(thing);
}
const isWorking = async () => elasticSearchCRUD("6334b9bb");
const notWorking = async () => elasticSearchCRUD("6334b9bb-27d4-43f3-aa45-162d6a497f32");
const run = async () => {
await isWorking();
await notWorking();
}
run();
$ ts-node test.ts
Creating thing with thingId: 6334b9bb
Before update
modelInstance {
thingId: '6334b9bb',
createdOn: '2018-09-04T09:52:17.156Z',
updatedOn: '2018-09-04T09:52:17.183Z',
id: 'AWWj_zkuFA-J_V5PmYxh' }
After update
modelInstance {
thingId: '6334b9bb',
createdOn: '2018-09-04T09:52:17.156Z',
updatedOn: '2018-09-04T09:52:17.183Z',
id: 'AWWj_zkuFA-J_V5PmYxh' }
After remove
modelInstance {
thingId: '6334b9bb',
createdOn: '2018-09-04T09:52:17.156Z',
updatedOn: '2018-09-04T09:52:19.217Z',
id: 'AWWj_zkuFA-J_V5PmYxh',
field: 'field' }
Creating thing with thingId: 6334b9bb-27d4-43f3-aa45-162d6a497f32
Before update
undefined
(node:53475) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'update' of undefined
at Object.<anonymous> (/Users/litterfeldt/Dev/kaching/v2_workspace/be-catalog/src/test.ts:25:17)
at Generator.next (<anonymous>)
at fulfilled (/Users/litterfeldt/Dev/kaching/v2_workspace/be-catalog/src/test.ts:4:58)
at <anonymous>
(node:53475) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:53475) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.