I am trying to use aggregations on nested type. I want to apply a nested
filter to apply aggs to a subset of docs, but when I do that the "terms"
aggregation counts nested docs, not parent docs. In other words, if same
term is found in two different nested documents belong to the same parent,
count will be two. I want it to count only once per parent document. Using
"include_in_parent" does not help because then I cannot apply the nested
Here is my gist showing three different approaches:
nested_aggs.sh: Did not use "include_in_parent". Counts "Role1" twice
instead of once.
nested_include.sh: Added "include_in_parent". Counts "Role1" once,
but also returns "Role2" since I cannot filter the nested docs.
nested_include_key.sh: My workaround for now. Using
"include_in_parent" plus added my filter into new field called
"roleAdminKey". Then on my aggregation I used "include" parameter to apply
I have posted my results in the gist as well. While #3 above works, my
actual mapping contains many more fields with multiple levels of nesting
and I'd like to be able to apply several other filtered aggregations on
nested types without having to add a "*Key" field for each one.
Is there a way to filter "terms" aggregations on nested types while
returning the count of parent docs, not nested docs?
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to email@example.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/6f3cfbf8-13aa-4c21-87e2-4eb54abc3995%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.