Reproducible gist: https://gist.github.com/brusic/81e1552ffd49a1f6a7aa
Surely I cannot be the only one to have encountered this issue. -- Ivan On Mon, Nov 10, 2014 at 12:53 PM, Ivan Brusic <i...@brusic.com> wrote: > Is it possible to aggregate only on the nested documents that are returned > by a (filtered) query? For what I can tell when using a nested aggregation, > it will function on all nested documents of the parent documents whose > nested document satisfy a nested query/filter. Did that make sense? :) Is > this the same limitation as issue #3022? I know that number by heart by now. > > For example, I have 3 simple documents, where the nstd object is defined > as nested: > > { > "name" : "foo", > "nstd" : [ > { > "ID" : 1 > } > ] > } > ' > > { > "name" : "bar", > "nstd" : [ > { > "ID" : 2 > } > ] > } > ' > > { > "name" : "baz", > "nstd" : [ > { > "ID" : 1 > }, > { > "ID" : 2 > } > ] > } > ' > > I then execute a simple nested query: > > "query": { > "filtered": { > "query": { > "match_all": {} > }, > "filter": { > "nested": { > "path": "nstd", > "filter": { > "term": { > "nstd.ID": 1 > } > } > } > } > } > } > > If I aggregate on the nstd.ID field, I will always get back results for > nested documents that were excluded by the filter: > > "buckets": [ > { > "key": 1, > "doc_count": 2 > }, > { > "key": 2, > "doc_count": 1 > } > ] > > Since the ID:2 field does not match the filter, it should not be returned > with the aggregation. I have tried using a filter aggregation with the same > filter used in the filtered query, but I receive the same results. > > Cheers, > > Ivan > -- 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 elasticsearch+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQBUa1XbQRoAtgoj71kjrgHOW5PS%3Dr08U2ZDie9HXKs_2A%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.