Open Shelagh-Lewins opened 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
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.
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'
Thanks! I'll probably come back to this on my next project.
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.
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.