Skip to content

Added filters aggregation #6119

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

Closed
wants to merge 1 commit into from
Closed

Added filters aggregation #6119

wants to merge 1 commit into from

Conversation

uboness
Copy link
Contributor

@uboness uboness commented May 11, 2014

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

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
@uboness uboness added the review label May 11, 2014
@uboness
Copy link
Contributor Author

uboness commented May 11, 2014

@rashidkpc @jpountz fyi

"filters" : {
"filters" : {
"errors" : { "query" : { "match" : { "body" : "error" } } },
"warnings" : { "query" : { "match" : { "body" : "error" } } }
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the 2nd query should look for warning in the body instead of error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

indeed

@jpountz
Copy link
Contributor

jpountz commented May 12, 2014

I like the way that this aggregation manages buckets (like the range agg). I left a couple of questions inlined.

@rashidkpc
Copy link

Love it, exactly what we needed.

@jpountz jpountz added v1.3.0 and removed v2.0.0 labels Jun 13, 2014
@s1monw
Copy link
Contributor

s1monw commented Jun 18, 2014

@uboness what's the status here? I remove the review tag for now...

@s1monw s1monw removed the review label Jun 18, 2014
@uboness
Copy link
Contributor Author

uboness commented Jun 18, 2014

I think it's pretty much ready... there's only a debate about the json structur... maybe @clintongormley can have a look

@s1monw
Copy link
Contributor

s1monw commented Jun 18, 2014

+1 thanks @uboness

@clintongormley
Copy link
Contributor

@uboness I think it should be:

{
     "aggs" : {
         "messages" : {
             "filters" : {
                 "errors" : { "query" : { "match" : { "body" : "error" } } },
                 "warnings" : { "query" : { "match" : { "body" : "error" } } }
             },
             "aggs" : { "monthly" : { "histogram" : { "field" : "timestamp", "interval" : "1M" } } }
         }
     }
 }

This fits nicely with the filter agg. It doesn't make sense to allow keyed because there is no intrinsic order to the keys of a hash in JSON. If you want the equivalent of keyed: false you could potentially support this format too:

{
     "aggs" : {
         "messages" : {
             "filters" : [
                 { "query" : { "match" : { "body" : "error" } } },
                 { "query" : { "match" : { "body" : "error" } } }
             ],
             "aggs" : { "monthly" : { "histogram" : { "field" : "timestamp", "interval" : "1M" } } }
         }
     }
 }

... but I think that's just providing options for the sake of it.

@uboness
Copy link
Contributor Author

uboness commented Jun 19, 2014

@clintongormley the idea behind the "keyed" version was to be future proof... it's consistent with other aggs, in the future if we'll need to add meta data to the application (which we actually working on doing in another PR #6465) it'll be mixed with the aggs data... and that's no good

@clintongormley
Copy link
Contributor

@uboness PR #6465 will work happily with my example structure. The meta element isn't part of the agg body:

{
     "aggs" : {
         "messages" : {
             "filters" : {
                 "errors" : { "query" : { "match" : { "body" : "error" } } },
                 "warnings" : { "query" : { "match" : { "body" : "error" } } }
             },
             "meta": { "foo": "bar" },
             "aggs" : { "monthly" : { "histogram" : { "field" : "timestamp", "interval" : "1M" } } }
         }
     }
 }

The filter agg doesn't have space for any extra params in the body either:

{
     "aggs" : {
         "messages" : {
             "filter" : {"query" : { "match" : { "body" : "error" } } }
             "meta": { "foo": "bar" }
         }
     }
 }

So the only distinction between these filter and filters is the existence of a key, which predicates returning the result as {keyed: true} (as {keyed: false} would be meaningless here.

@uboness
Copy link
Contributor Author

uboness commented Jun 19, 2014

@clintongormley actually, you're right... my bad.. will work to see how it works out, thx

@colings86 colings86 self-assigned this Jul 16, 2014
@colings86
Copy link
Contributor

Closing as PR 6974 supersedes this

@colings86 colings86 closed this Aug 1, 2014
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.

Aggregations: Add filters aggregation
6 participants