-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Added Filters aggregation #6974
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
Conversation
LGTM, @rashidkpc mind looking at it for the proposed API format? |
API looks good so far. I'm going to build this, try to integrate it into Kibana 4 and see how it goes. |
Ok, I prototyped this out and got it working in Kibana 4. The only input I have into the API format is that it is, slightly, inconsistent with how we do other aggregations that require the buckets to be explicitly defined. The currently proposed filters agg format looks like this:
Its a bit awkward, since the keys of the of filters agg are not configuration parameters, but rather names. We don't do that anywhere else. The only other place were we have explicit definitions of buckets like this in in the range agg, where we use an array to define the ranges:
I wonder if we should do the same thing, and return the buckets as an array, like the range agg does. Granted if we did this with the filters agg we'd end up with filters.filters, which is also weird:
Of course, you bring up a good point, people might want the response to be keyed. In which case, we could again use the convention defined by the range agg, using the keyed property (http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-range-aggregation.html#_keyed_response) If we wanted to do the same thing in the filters agg we could use the _name convention from named filters/queries (http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-named-queries-and-filters.html). Eg:
I don't love the filters.filters thing, but it is consistent. |
@rashidkpc I'm not sure we need the This assumes that Jackson and client languages can differentiate. @polyfractal - I know that PHP does some funky things with converting hashes to arrays, but I think that's only for empty hashes? |
Hmm, I may have to eat my words about not requiring the |
Updated so that you request is filters.filters again and can support providing an array of anonymous filters in the request which are returned in the same order in the response. Not sure if I like it however, since unlike the histogram aggregator the 'keyed: false' option does not have a key field which links back to the request so the only link between the bucket in the response and the filter in the request is its position in the array |
@colings86 (Ignore my comments about #7020 ) Not sure we need the double level |
@rashidkpc can you confirm that you'd be happy with support for these two syntax options? Results returned with keys:
Results returned as an array:
|
After reviewing the range aggregation, I understand why the syntax is how it is. I think the syntax as proposed by @clintongormley will be fine for the filters aggregation. |
w00t |
Tried to implement this but the aggregation framework throws an error if the aggregation is not an object so does not work for the Array case. At least for the array case we may need to go back to having filters.filters as it doesn't seem correct to change the agg framework for what seems like a special case here. thoughts? |
because of the above issue the syntax is going to stay as the following: Results returned with keys:
Results returned as an array:
|
*/ | ||
public class FiltersAggregationBuilder extends AggregationBuilder<FiltersAggregationBuilder> { | ||
|
||
private Map<String, FilterBuilder> filters = new HashMap<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should it be a linked hash map so that the order would be the same in the response?
@colings86 Left some comments. |
@jpountz I implemented thhe changes you suggested and also I added tests and documentation for array type request as well as updating the Builder to be able to construct array requests since I realised these were missing |
LGTM |
A multi-bucket aggregation where multiple filters can be defined (each filter defines a bucket). The buckets will collect all the documents that match their associated filter. This aggregation can be very useful when one wants to compare analytics between different criterias. It can also be accomplished using multiple definitions of the single filter aggregation, but here, the user will only need to define the sub-aggregations only once. Closes #6118
@JasonPunyon fixed, thanks |
A multi-bucket aggregation where multiple filters can be defined (each filter defines a bucket). The buckets will collect all the documents that match their associated filter.
This aggregation can be very useful when one wants to compare analytics between different criterias. It can also be accomplished using multiple definitions of the single filter aggregation, but here, the user will only need to define the sub-aggregations only once.
(this is a continuation of Pull Request #6119)
Closes #6118,#6119