Skip to content

Conversation

kevinbuhmann
Copy link
Contributor

@kevinbuhmann kevinbuhmann commented Jun 4, 2019

The problem is similar to #2336 except with SignificantTermsBucket instead of KeyedBucket. My use case is significant terms aggregation over numeric terms. But SignificantTermsBucket.Key is always null due to the Key = (string)key line in AggregateFormatter.

This solution is modeled after the solution for KeyedBucket in 91f1f81.

I have based this PR on master but if this could also be targeted for 6.x, I would be very appreciative. I can open a separate PR targeting the 6.x branch if necessary.

Let me know if there are any changes needed. I would be happy to comply.

@kevinbuhmann kevinbuhmann force-pushed the sig-term-agg-generic-key branch 2 times, most recently from d114ce7 to 399747e Compare June 4, 2019 05:30
Copy link
Member

@Mpdreamz Mpdreamz left a comment

Choose a reason for hiding this comment

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

Awesome awesome PR thanks for raising it @kevinphelps

Left a couple of nitpicks.

Backporting to 6.x might be a tad harder as SignificantTermsAggregate SignificantTermsBucket are now generic, we could look into keeping both the non generic and generic versions of those in that branch though

Meta = bucket.Meta
};
}

public SignificantTermsAggregate SignificantText(string key)
public SignificantTermsAggregate<TKey> SignificantText<TKey>(string key)
Copy link
Member

Choose a reason for hiding this comment

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

I think having a non generic overload defaulting to TKey as string would be a nicer experience for the most common case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can add that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is done.

{
Key = (string)key,
Copy link
Member

Choose a reason for hiding this comment

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

key is known to be only string or double from where its called:

		private IBucket GetKeyedBucket(ref JsonReader reader, IJsonFormatterResolver formatterResolver)

perhaps we can use this to our advantage and instantiate either a SignificantTermBucket<string> or SignificantTermBucket<double> and then use this type information in

private IEnumerable<SignificantTermsBucket<TKey>> GetSignificantTermsBuckets<TKey>(IEnumerable<IBucket> items)	

To return the items (casted) directly instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You could do the same thing in GetKeyedBucket. Should that one be refactored as well?

@kevinbuhmann
Copy link
Contributor Author

Awesome awesome PR thanks for raising it @kevinphelps

Thanks! I'll try to make the requested changes tomorrow! :)

Backporting to 6.x might be a tad harder as SignificantTermsAggregate SignificantTermsBucket are now generic, we could look into keeping both the non generic and generic versions of those in that branch though

That sounds like it could work, but if not it's alright. I've already forked 6.x internally, so it's no big deal for me at least.

@kevinbuhmann kevinbuhmann force-pushed the sig-term-agg-generic-key branch from 399747e to fc59906 Compare June 12, 2019 19:53
Copy link
Member

@Mpdreamz Mpdreamz left a comment

Choose a reason for hiding this comment

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

This LGTM thanks for updating the PR @kevinphelps

@russcam russcam changed the base branch from master to 7.x June 27, 2019 11:08
@russcam russcam changed the base branch from 7.x to master June 27, 2019 11:09
russcam added a commit that referenced this pull request Jun 27, 2019
Supersedes: #3795

Key of SignificantTermsBucket is generic to allow for returning
both string and numeric key values.

Co-authored-by: kevinphelps <KevinPhelps11@gmail.com>
@russcam
Copy link
Contributor

russcam commented Jun 27, 2019

@kevinphelps I'm going to close this PR in favour of #3890, as we're pulling it into 7.x and retargeting introduces a few merge conflicts to resolve.

I've added you as co-author 👍

@russcam russcam closed this Jun 27, 2019
russcam added a commit that referenced this pull request Jun 27, 2019
Supersedes: #3795

Key of SignificantTermsBucket is generic to allow for returning
both string and numeric key values.

Co-authored-by: kevinphelps <KevinPhelps11@gmail.com>
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.

3 participants