zackiles / elasticsearch-odm

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Simple find() Query not working!

Ahmadhussain92 opened this issue · comments

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

What is your version of Elasticsearch ?

  • If you are using Elasticsearch 2.x you can try using elasticsearch-odm-2
  • If you are using Elasticsearch 5.x you can try using elasticsearch-odm-5

It's a forked of zackiles with some adaptation to work with elasticsearch 2 or 5.

Seems Epsilonn2/elasticsearch-odm is also updated frequently and support es5.x

Try again with one of this fork.