matteodem / meteor-easy-search

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

Documentation missing for elastic search #643

Open Shelagh-Lewins opened 5 years ago

Shelagh-Lewins commented 5 years ago

The docs for choosing engines have a broken link to elastic search instructions:

http://matteodem.github.io/meteor-easy-search/docs/engines/

https://github.com/matteodem/meteor-easy-search/tree/master/packages/easysearch:elasticsearch

Is elastic search no longer supported? Or have the instructions moved?

Thank you for this great package which still seems to be the go-to search package for Meteor.

Shelagh-Lewins commented 5 years ago

I tried to get elasticsearch working but no luck. I installed elasticsearch and checked the service is running.

I then added the elasticsearch package:

meteor add easysearch:elasticsearch@=2.1.0

and tried to use the elasticsearchengine in my template:

import { Index, ElasticSearchEngine } from 'meteor/easy:search';
import { Projects } from '../schemas/schemas';

// On Client and Server
const UsersIndex = new Index({
    'collection': Meteor.users,
    'defaultSearchOptions': { 'limit': 10 },
    'fields': ['username', 'email'],
    'engine': new ElasticSearchEngine(),
});

I got a server error:
TypeError: ElasticSearchEngine is not a constructor
meecect commented 5 years ago

I was able to get it running, but you have to make a few modifications as ElasticSearch has deprecated a few things.

For one, easy-search composes an elastic search 'body' that specifies a 'fields' property. That is no longer the right way to specify the return values. You should use '_source'.

Next, if the fields you are indexing (for the easy search collection) have a 'text' type, easy search adds them by default to the 'sort' option to elastic, but that causes elastic to throw an error but it warns you about putting text types in memory for sorting and aggregating.

So I was able to at least get it to work (maybe not an ideal way) by doing this:

export const PostsElasticIndex = new Index({
  collection: Posts,
  name: 'postsElasticIndex',
  fields: ['title','content'],
  engine: new ElasticSearchEngine({
    body: function(body, options) {
      delete body.fields;
      delete body.sort;
      body._source= '_id';
      return body;
     } // modify the body that's sent when searching
  }),
  defaultSearchOptions: { limit: 25 }, // default options when searching

})

I can provide more details if this is still something you need.

meecect commented 5 years ago

oh, also, you need to explicitly include the elastic engine, so this:

meteor add easysearch:elasticsearch

and:

import { Index, MongoDBEngine } from 'meteor/easy:search'
import { ElasticSearchEngine } from 'meteor/easysearch:elasticsearch'
Shelagh-Lewins commented 5 years ago

Thanks! I'll probably come back to this on my next project.

matteodem commented 3 years ago

The docs are here https://github.com/matteodem/meteor-easy-search/tree/master/packages/easysearch_elasticsearch Any pr fixing the links in the gh-pages branch are greatly appreciated.