# Statistical facet for complex nested documents

**URL:** <https://discuss.elastic.co/t/statistical-facet-for-complex-nested-documents/13301>\
**Category:** Elasticsearch\
**Created:** [August 22, 2013, 1:52pm UTC](https://discuss.elastic.co/t/statistical-facet-for-complex-nested-documents/13301 "2013-08-22T13:52:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gregory](https://avatars.discourse-cdn.com/v4/letter/g/e56c9b/32.png) [@Gregory](https://discuss.elastic.co/u/Gregory)\
**Post date:** [August 22, 2013, 1:52pm UTC](https://discuss.elastic.co/t/statistical-facet-for-complex-nested-documents/13301/1 "2013-08-22T13:52:46Z")

</div>

I have mapping for product like listed below:

**{  
"PRODUCT" : {  
"properties" : {  
......................  
"price" : {  
"type" : "nested",  
"properties" : {  
"id" : {  
"type" : "string"  
},  
"type" : {  
"type" : "string"  
},  
"value" : {  
"properties" : {  
"gb" : {  
"type" : "long"  
},  
"fr" : {  
"type" : "long"  
},  
"usa" : {  
"type" : "long"  
},  
"rus" : {  
"type" : "long"  
},  
"grmn" : {  
"type" : "long"  
}  
}  
},  
"test" : {  
"type" : "long"  
}  
}  
}  
.........................  
}  
}  
}**  
Here is example of object:  
**{  
.................  
"price" : [{  
"id" : "default",  
"type" : "price",  
"value" : {  
"gb" : 2290,  
"grmn" : 2290  
"fr" : 2250,  
"usa" : 1980,  
"rus" : 73280,  
},  
"test" : 1  
}, {  
"id" : "usCristmasPromo",  
"type" : "promo",  
"value" : {  
"gb" : 2290,  
"grmn" : 2290  
"fr" : 2250,  
"usa" : 1760,  
"rus" : 73280,  
},  
"test" : 1  
}, {  
"id" : "regularCustomerDiscount",  
"type" : "promo",  
"value" : {  
"gb" : 2175,  
"grmn" : 2175  
"fr" : 2137,  
"usa" : 1881,  
"rus" : 69616,  
},  
"test" : 1  
}  
],  
........................  
}**  
Each product have one 'default' price object with type='price' and dozens prices with type='promo'. In field id name of promotion action stores. User have region property (gb/fr/grmn/rus) and several promotions (some of them global, some only for regular customers). I need to build statistical facet (min/max) for price value. That query works well;

**{  
"size" : 10,  
"query" : {  
....................  
},  
"sort" : [{  
"price.value.usa" : {  
"order" : "asc",  
"mode" : "min",  
"nested\_filter" : {  
"terms" : {  
"price.id" : [  
"regularCustomerDiscount",  
"default"  
]  
}  
}  
}  
}  
],  
"facets" : {  
"priceStatistic" : {  
"nested" : "price",  
"statistical" : {  
 _"field" : "test"_  
},  
"facet\_filter" : {  
"terms" : {  
"price.id" : [  
"regularCustomerDiscount",  
"default"  
]  
}  
}  
}  
}  
}**

But if i change **"field" : "test"** for **"field" : "value.usa"** i will recieve exception:  
_nested: FacetPhaseExecutionException[Facet [priceStatistic]: No mapping found for field [value.usa]_  
I test different variations:  
"script": "doc['value.usa'].value"  
"script": "doc['value']['usa'].value"  
"script": "doc.get('value').get('usa').value"  
"script": "doc.get('value.usa').value"  
"script": "doc.value.usa.value"

and etc, but no one work.  
how can i recive min/max price of products in query for regular customer from usa region? ☹

---

<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 6, 2017, 2:20am UTC](https://discuss.elastic.co/t/statistical-facet-for-complex-nested-documents/13301/2 "2017-07-06T02:20:09Z")

</div>


