Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ES aggregations #601

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

ES aggregations #601

wants to merge 3 commits into from

Conversation

bompi88
Copy link
Contributor

@bompi88 bompi88 commented Apr 23, 2017

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
Copy link
Owner

wow, good stuff! looking forward

@bompi88 bompi88 force-pushed the aggs branch 3 times, most recently from ecd4e1d to 96c9d0b Compare April 25, 2017 07:47
if (collectionScope._indexConfiguration.countUpdateIntervalMs) {
intervalID = Meteor.setInterval(
() => this.changed(
collectionName,
'searchCount' + definitionString,
{ count: cursor.mongoCursor.count() }
// TODO: I substituted cursor.mongoCursor.count with cursor.count. will this break things?
{ count: cursor.count && cursor.count() || 0 }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matteodem Will this still work for mongo?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you'd have to check out all useages of the core Cursor and check if it's simply the mongoCursor.count() that's passed in. I'm not sure about that

@bompi88
Copy link
Contributor Author

bompi88 commented Apr 25, 2017

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

@bompi88 bompi88 force-pushed the aggs branch 2 times, most recently from c236ca5 to 7e0dffc Compare April 25, 2017 14:40
@bompi88 bompi88 changed the title WIP: ES aggregations. ES aggregations. Apr 25, 2017
@bompi88 bompi88 changed the title ES aggregations. ES aggregations Apr 25, 2017
@bompi88
Copy link
Contributor Author

bompi88 commented Apr 25, 2017

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

@matteodem
Copy link
Owner

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
Copy link
Contributor Author

bompi88 commented Apr 26, 2017

done !

@matteodem
Copy link
Owner

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

if (collectionScope._indexConfiguration.countUpdateIntervalMs) {
intervalID = Meteor.setInterval(() => {
let newCount;
Copy link
Contributor Author

@bompi88 bompi88 Apr 29, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matteodem It seems that the cursor.count() returns the initial count value set while instantiating the cursor, so I added a optional mongoCount parameter that is set to false by the ESCursor. Is this a satisfiable solution or should I do it otherwise?

@matteodem
Copy link
Owner

any progress on this?

@bompi88
Copy link
Contributor Author

bompi88 commented Jun 4, 2017

@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
Copy link
Owner

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants