GithubHelp home page GithubHelp logo

zackiles / elasticsearch-odm Goto Github PK

View Code? Open in Web Editor NEW
77.0 77.0 29.0 99 KB

Like Mongoose but for Elasticsearch. Define models, preform CRUD operations, and build advanced search queries.

License: MIT License

JavaScript 100.00%

elasticsearch-odm's People

Contributors

jdylanstewart avatar kodypeterson avatar krivil avatar zackiles avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

elasticsearch-odm's Issues

Check compatibility with 2.0

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.

child/parent relationships

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

Basic example not working

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

Simple find() Query not working!

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

Calls to connect() when no index exists hangs on first start.

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.

Problem with 'text' & 'keyword'

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.

Connect example fails with "TypeError: ConnectionError is not a function"

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.

Observations

  • The index did not already exist, but if something is wrong with the ES server, this isn't the place to troubleshoot that
  • Filling out an options object for the connect call produces the same result
  • Logging ConnectionError from index.js, just after the requires, shows that it is undefined

Boolean false fails to validate when required is true

The 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.

Elasticsearch 5.4

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

Id's with "-" not found when using findOne.

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.