matteodem / meteor-easy-search

Easy-to-use search for Meteor with Blaze Components
MIT License
438 stars 68 forks source link

TypeError exceptions thrown on server with ElasticSearch when no results are found #575

Closed RequestForCoffee closed 7 years ago

RequestForCoffee commented 7 years ago

Exception in setInterval callback: TypeError: cursor.mongoCursor.count is not a function at packages/easysearch:core/lib/core/search-collection.js:189:37 at [object Object]._.extend.withValue (packages\meteor.js:1122:17) at packages\meteor.js:445:45 at runWithEnvironment (packages\meteor.js:1176:24)

ghost commented 7 years ago

Have the same issue. Using the latest version.

Exception in setInterval callback: TypeError: cursor.mongoCursor.count is not a function
at packages/easysearch:core/lib/core/search-collection.js:193:41
at [object Object]._.extend.withValue (packages\meteor.js:1122:17)
at packages\meteor.js:445:45
at runWithEnvironment (packages\meteor.js:1176:24)

I have tried to debug search-collection.js but never gets error like that so, I assume, there is some timing issue or smth like that.

matteodem commented 7 years ago

any simple reproduction steps?

AdrianAbba commented 7 years ago
export const ProjectsIndex = new Index({
  collection: Projects,
  fields: ['title'],
  engine: new ElasticSearchEngine({ 
     body: function(){
       body = {query:{match:{title:"Wooden"}},"_source":["title"]};
       return body
     }
  }),
});

getting the same Exception

AdrianAbba commented 7 years ago

the Errors appears even if the searchObject is empty :/

those templates doesnt fix the error.

{{#EasySearch.IfInputEmpty index=projectsIndex}}
{{/EasySearch.IfInputEmpty}}  

{{#EasySearch.IfNoResults index=projectsIndex}}
   NO RESULTS!!!!
{{/EasySearch.IfNoResults}}

another tipp for ppl who have problems with the newst version of ElasticSearch and this package:

export const ProjectsIndex = new Index({
  collection: Projects,
  fields: ["title"],
  engine: new ElasticSearchEngine({
    query: (searchObject) => {
      match : {
            "title" : searchObject.title
        }
     }
  }, 
  body:(body) => {
     body._source = ["_id"];
     delete body.fields;
     delete body.sort; //optional
     return body;
  },

  }),
});

u have just to rebuild the body for the newst syntax of elasticSearch =)

sonnguyenthai commented 7 years ago

Hello. I got the same error. Is there any fix for it?

sonnguyenthai commented 7 years ago

Not sure if this is still helpful. But I found out that this error occurs when there is no result returned from searching. In this case, the cursor is an emptyCursor which has no count. So we get this error.

static get emptyCursor() {
    return { fetch: () => [], observe: () => { return { stop: () => null }; }, stop: () => {} };
  }

For people who intend, here is my setup for ElasticSearchEngine to work with the newest changes of ElasticSearch https://gist.github.com/sonnguyenthai/91164e0b4ccf1c878930bc9febb4f7dc. And as @AdrianAbba said, you should build your own query to match your requires

matteodem commented 7 years ago

feel free to create a PR with these fixes included

matteodem commented 7 years ago

Fix by @bompi88 is now released, please test this in the latest release v2.1.7