meteor-easy-search icon indicating copy to clipboard operation
meteor-easy-search copied to clipboard

Documentation missing for elastic search

Open Shelagh-Lewins opened this issue 5 years ago • 5 comments

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 avatar Mar 15 '19 10:03 Shelagh-Lewins

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

Shelagh-Lewins avatar Mar 15 '19 14:03 Shelagh-Lewins

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 avatar Oct 21 '19 15:10 meecect

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'

meecect avatar Oct 21 '19 15:10 meecect

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

Shelagh-Lewins avatar Oct 22 '19 14:10 Shelagh-Lewins

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.

matteodem avatar Sep 19 '21 13:09 matteodem