-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Looping Named Buckets #1742
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
Comments
Here's how you would do it in NEST 2.x var names = new[] {
((int)RepeatBuyersGrouping.One).ToString(),
((int)RepeatBuyersGrouping.TwoFive).ToString()
};
var response = client.Search<Example>(s => s
.Aggregations(aggs => aggs
.Filters("repeatBuyers", fil => fil
.NamedFilters(f => f
.Filter(names[0], q => q
.Range(ra => ra
.Field(of => of.TotalOrders)
.LessThanOrEquals(1)))
.Filter(names[1], q => q
.Range(ra => ra
.Field(of => of.TotalOrders)
.GreaterThan(1)
.LessThanOrEquals(5))
)
)
)
)
);
var filters = response.Aggs.Filters("repeatBuyers");
foreach (var name in names)
{
var filter = filters.NamedBucket(name);
// do something with filter
} The |
To clarify, what you are suggesting is to no longer loop the buckets as such but the array I have that I used to make the different buckets. I tried your code and it seems to work (will check more over coming days) I feel like the Thanks! |
As a quick follow up, I wanted to test making these public, so I compiled the repo locally and changed just the FiltersBucket setting the |
@RobinRieger cool! Feel free to submit a PR with the change 👍 |
Closed via #1752 |
Is there a way in 2.0 to loop over named buckets (aggregations)?
In 1.7 I was able to do the following
The search looked something like this:
This way I could use the bucket name and the value in the output. I.e. The name of each bucket is a integer and it maps to an enum which I can then use to get the proper 'display' text' for the output.
With 2.0, I can't seem to loop the 'NamedBucket'. Do I need to call them separately now or was this accidentally dropped?
The text was updated successfully, but these errors were encountered: