# Nested Range Aggregation

**URL:** <https://discuss.elastic.co/t/nested-range-aggregation/115943>\
**Category:** Elasticsearch\
**Created:** [January 17, 2018, 7:52pm UTC](https://discuss.elastic.co/t/nested-range-aggregation/115943 "2018-01-17T19:52:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mike88](https://avatars.discourse-cdn.com/v4/letter/m/a587f6/32.png) [@Mike88](https://discuss.elastic.co/u/Mike88)\
**Post date:** [January 17, 2018, 7:52pm UTC](https://discuss.elastic.co/t/nested-range-aggregation/115943/1 "2018-01-17T19:52:28Z")

</div>

Hi there,

Based on the following data:

"hits": {  
"total": 2,  
"hits": [  
{  
"\_id": "PRODUCT A",  
"inner\_hits": {  
"doc.products": {  
"hits": {  
"total": 1,  
"hits": [  
{  
"doc.products.productCode": "PRODUCT A",  
"inner\_hits": {  
"doc.products.calculatedPrices": {  
"hits": {  
"hits": [  
{  
"doc.products.calculatedPrices.now": 100  
}  
]  
}  
}  
}  
}  
]  
}  
}  
}  
},  
{  
"\_id": "PRODUCT B",  
"inner\_hits": {  
"doc.products": {  
"hits": {  
"total": 2,  
"hits": [  
{  
"doc.products.productCode": "PRODUCT B",  
"inner\_hits": {  
"doc.products.calculatedPrices": {  
"hits": {  
"doc.products.calculatedPrices.now": 200  
},  
{  
"doc.products.calculatedPrices.now": 201  
}  
]  
}  
}  
}  
},  
{  
"doc.products.productCode": "PRODUCT B",  
"inner\_hits": {  
"doc.products.calculatedPrices": {  
"hits": {  
"doc.products.calculatedPrices.now": 300  
},  
{  
"doc.products.calculatedPrices.now": 301  
},  
{  
"doc.products.calculatedPrices.now": 302  
}  
]  
}  
}  
}  
}  
]  
}  
}  
}  
}  
]  
}

Is it possible to do a range aggregation based on the lowest calculated price for all the products for each document and uses that value, for the range, something like this

"prices": {  
"price\_ranges": {  
"prices": {  
"buckets": {  
"0-200": {  
"from": 0,  
"to": 199,  
"price\_range\_count": {  
"doc\_count": 1  
}  
},  
"200-399": {  
"from": 200,  
"to": 399,  
"price\_range\_count": {  
"doc\_count": 1  
}  
}  
}  
}  
}  
}

Thank you in advance

---

<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:** [February 14, 2018, 7:52pm UTC](https://discuss.elastic.co/t/nested-range-aggregation/115943/2 "2018-02-14T19:52:37Z")

</div>

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