Navigation Menu

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

Add reverse nested aggregation #5485

Closed
martijnvg opened this issue Mar 21, 2014 · 4 comments
Closed

Add reverse nested aggregation #5485

martijnvg opened this issue Mar 21, 2014 · 4 comments

Comments

@martijnvg
Copy link
Member

Similar to the nested aggregator, but in reverse. It allows to create buckets and metrics based on the parent docs in the buckets of child documents.

This aggregation only makes sense inside a nested aggregator. Assume a ticket system with where the comments are embedded into the issue document. The reverse_nested aggregator would look like this:

"aggs" : {
   "top_commenters_to_issues" : {
        "nested" : {"path" : "comments"},
        "aggs" : {
            "top_commenters" : {
                "terms" : { "field" : "username" },
                "aggs" : {
                    "top_tags_to_comments" : {
                        "reverse_nested" : {
                            "path" : "comments"
                        },
                        "aggs" : {
                            "top_tags" : { "terms" : { "field" :  "tags"}}
                        }    
                    }
                }
            }
        }
    }
}

This aggregation would return top username buckets and per username bucket the top tags. The important constraint that the nested and reverse_nested add here is that only tag buckets are associated to username buckets that reside in the nested structure.

@martijnvg
Copy link
Member Author

Closed via: be12bcd

@speedplane
Copy link
Contributor

This little feature is actually quite amazing. Aggregations can now get really complex and powerful.

@orenorgad
Copy link

Are we be able to filter the nested documents for which the aggregation will work on?
e.g, let's say I want to aggregate comments registered on specific date range (and of course distinct users). Is this possible at the moment?

@speedplane
Copy link
Contributor

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

No branches or pull requests

4 participants