# Do subaggregations perform AND operation?

**URL:** <https://discuss.elastic.co/t/do-subaggregations-perform-and-operation/88275>\
**Category:** Kibana\
**Created:** [June 5, 2017, 1:46pm UTC](https://discuss.elastic.co/t/do-subaggregations-perform-and-operation/88275 "2017-06-05T13:46:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![initproto](https://avatars.discourse-cdn.com/v4/letter/i/74df32/32.png) [@initproto](https://discuss.elastic.co/u/initproto)\
**Post date:** [June 5, 2017, 1:46pm UTC](https://discuss.elastic.co/t/do-subaggregations-perform-and-operation/88275/1 "2017-06-05T13:46:00Z")

</div>

Hi,  
If I have a a document with child parts to it like this:

{  
"type":"document",  
"properties": [  
{  
"this":"THIS",  
"that":"THAT"  
}  
],  
"metadata": {  
"count":"1",  
"sum":"2"  
}

If I build and aggregation with properties.this and then a sub aggregation with properties.that, will the aggregate documents combine the values of "this" and "that" within the same element (AND opreation), or in different elements across the document (OR operation)?

Same with sub element metadata. if I aggregate and do a sub bucket on both fields, I want them to be ANDed in my visualization.

thanks

---

<div class="post-metadata">

**Author:** ![thomasneirynck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thomasneirynck/32/23313_2.png) [@thomasneirynck](https://discuss.elastic.co/u/thomasneirynck)\
**Post date:** [June 5, 2017, 3:29pm UTC](https://discuss.elastic.co/t/do-subaggregations-perform-and-operation/88275/2 "2017-06-05T15:29:15Z")

</div>

hi @initproto,

not sure if I follow a 100% given the example document you gave, and what element exactly refers to, so let me know if my answer is beside the question.

Metrics calculated for a sub-aggregation will apply to the inner product of the aggregation-hierarchy.

So if you compute metrics for a terms aggregation on `.this` with a sub-aggregation for a terms-aggregation on `.that`, it will compute the metrics for all combinations of the .this and .that values that are present in the documents of your index. That said, it's not really ALL aggregations, because you cap your query to ES with the size-parameter. The order in which the aggregations are defined, defines the priority in which they are evaluated.

thx,

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 3, 2017, 3:29pm UTC](https://discuss.elastic.co/t/do-subaggregations-perform-and-operation/88275/3 "2017-07-03T15:29:30Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
