matteodem / meteor-easy-search

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

ES aggregations #601

Open bompi88 opened 7 years ago

bompi88 commented 7 years ago

Implementing Elasticsearch aggregations, which are published together with the hits data.

In current implementation, the aggregations are injected in the body function like so:

var index = new EasySearch.Index({
  ...
  engine: new EasySearch.ElasticSearch({
    'body': function(body, opts) {
      body.aggs = {
        tags:{
          filter: {},
          aggs: {
            tags: {
              terms: { field: 'tags.raw' }
            }
          }
        }
      };
      return body;
    }
    ...
  }
});

and gets accessible on the cursor returned by the search method like this:

var cursor = index.search('test');

// get all aggregations
cursor.getAggregations();

// get aggregation by name
cursor.getAggregation('tags');
matteodem commented 7 years ago

wow, good stuff! looking forward

bompi88 commented 7 years ago

Test app is available at https://github.com/bompi88/easy-search-leaderboard. The filters are retrieved from ES aggregations.

bompi88 commented 7 years ago

@matteodem thanks for quick merging 😄 have you looked at this PR? some things you like me to add or modify?

matteodem commented 7 years ago

Can you add a useage example of this aggregations functionality to the elasticsearch README? with the component methods and so on.

Otherwise good job!

bompi88 commented 7 years ago

done !

matteodem commented 7 years ago

still got a comment open, can you have a look at that? otherwise it's fine to merge for me

matteodem commented 7 years ago

any progress on this?

bompi88 commented 7 years ago

@matteodem The progress stalled. I'm not sure where I should precede from here? You want me to extend the core's SearchCollection, to extract the Elasticsearch specific code?

matteodem commented 7 years ago

@bompi88 I think it'd be much cleaner to put the aggregation logic into the ESSearchCollection and only change the core SearchCollection as to make this easily possible. Maybe add a onPublish() method on the class that can be overriden by ESSearchCollection to publish the aggregation data.

Also the cursor.mongoCursor.count logic in the setInterval might also be changed to be a cursor.cursorCount method or accessor that can be overridden by the ESCursor, so that there doesn't have to be any "mongCount" and other logic in the core.

This is all with the goal to keep elastic search related logic out of the core code. Hope it makes sense