# Special case of aggregate query

**URL:** <https://discuss.elastic.co/t/special-case-of-aggregate-query/186668>\
**Category:** Elasticsearch\
**Created:** [June 20, 2019, 11:30am UTC](https://discuss.elastic.co/t/special-case-of-aggregate-query/186668 "2019-06-20T11:30:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pavan\_Kundgol](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pavan_kundgol/32/48436_2.png) [@Pavan\_Kundgol](https://discuss.elastic.co/u/Pavan_Kundgol)\
**Post date:** [June 20, 2019, 11:30am UTC](https://discuss.elastic.co/t/special-case-of-aggregate-query/186668/1 "2019-06-20T11:30:18Z")

</div>

Hi Team ,

I have documents stored in ES with below structure :

## Column1 | Column2 | Column3

Doc1 | P1 | T1  
Doc2 | P1 |  
Doc3 | P1 |  
Doc4 | P2 |  
Doc5 | P2 | T2  
Doc6 | P2 |  
Doc7 | P3 | T1  
Doc8 | P3 |

Is there a way in ES to aggregate on Col3 , but while aggregating pre-fill empty values of col3 with value based on matching condition ?

Like if I use general ES aggs aggregate on Col3 , the aggregate would consider data something like  
T1 -\>[Doc1,Doc7]  
T2-\>[Doc5]

But , I want aggregate to consider data as below :  
T1-\>[Doc1,Doc2,Doc3,Doc7,Doc8]  
T2-\>[Doc4,Doc5,Doc6]

i.e it should consider documents based on matching value of Col2 of relative non-empty value of aggregate column Col3.

For ex : For Agg T2 , Doc4 and Doc6 is considered , on the basis that they have same col2 value (P2) as that of Doc5.

---

<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 18, 2019, 11:30am UTC](https://discuss.elastic.co/t/special-case-of-aggregate-query/186668/2 "2019-07-18T11:30:18Z")

</div>

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