# Visualization for nested aggregations

**URL:** <https://discuss.elastic.co/t/visualization-for-nested-aggregations/211642>\
**Category:** Kibana\
**Created:** [December 12, 2019, 11:53am UTC](https://discuss.elastic.co/t/visualization-for-nested-aggregations/211642 "2019-12-12T11:53:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pablo\_Albertengo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pablo_albertengo/32/47685_2.png) [@Pablo\_Albertengo](https://discuss.elastic.co/u/Pablo_Albertengo)\
**Post date:** [December 12, 2019, 11:53am UTC](https://discuss.elastic.co/t/visualization-for-nested-aggregations/211642/1 "2019-12-12T11:53:58Z")

</div>

I am trying to create a visualization in Kibana from a Nested Aggregation but I am not finding the way.

What I did now was to adapt another aggregation to be able to add a nested field and it brings me the desired results if I query ElasticSearch directly.

Below are the index definition and the mentioned aggregation.

Do I have any way to create a visualization from that query?  
What other way do I have?

Index:  
{  
"hotelssearch": {  
"mappings": {  
"properties": {  
"beginDt": {  
"type": "date",  
"format": "yyyy-MM-dd HH:mm:ss"  
},  
"checkIn": {  
"type": "date"  
},  
"checkOut": {  
"type": "date"  
},  
"clientConfiguration": {  
"type": "nested",  
"properties": {  
"duplicatesRemove": {  
"type": "boolean"  
},  
"timeout": {  
"type": "long"  
}  
}  
},  
"clientName": {  
"type": "keyword"  
},  
"contractId": {  
"type": "integer"  
},  
"countryCode": {  
"type": "keyword"  
},  
"destinationId": {  
"type": "integer"  
},  
"destinationName": {  
"type": "keyword"  
},  
"endDt": {  
"type": "date",  
"format": "yyyy-MM-dd HH:mm:ss"  
},  
"login": {  
"type": "keyword"  
},  
"occupancy": {  
"type": "keyword"  
},  
"resultsCount": {  
"type": "integer"  
},  
"searchId": {  
"type": "keyword"  
},  
"searchTime": {  
"type": "integer"  
},  
"suppliersDiscardedByBusinessRules": {  
"type": "nested",  
"properties": {  
"detailedMessage": {  
"type": "text",  
"fields": {  
"keyword": {  
"type": "keyword",  
"ignore\_above": 256  
}  
}  
},  
"id": {  
"type": "text",  
"fields": {  
"keyword": {  
"type": "keyword",  
"ignore\_above": 256  
}  
}  
},  
"ruleType": {  
"type": "text",  
"fields": {  
"keyword": {  
"type": "keyword",  
"ignore\_above": 256  
}  
}  
},  
"supplierId": {  
"type": "text",  
"fields": {  
"keyword": {  
"type": "keyword",  
"ignore\_above": 256  
}  
}  
},  
"supplierName": {  
"type": "text",  
"fields": {  
"keyword": {  
"type": "keyword",  
"ignore\_above": 256  
}  
}  
}  
}  
},  
"suppliersEnabled": {  
"type": "nested",  
"properties": {  
"supplierId": {  
"type": "text",  
"fields": {  
"keyword": {  
"type": "keyword",  
"ignore\_above": 256  
}  
}  
},  
"supplierName": {  
"type": "text",  
"fields": {  
"keyword": {  
"type": "keyword",  
"ignore\_above": 256  
}  
}  
}  
}  
},  
"userId": {  
"type": "integer"  
}  
}  
}  
}  
}

Aggregation:  
{  
"aggs" : {  
"suppliersEnabledCount" : {  
"nested" : {  
"path" : "suppliersEnabled"  
},  
"aggs" : {  
"suppliers\_Enabled\_Count" : { "terms" : { "field" : "suppliersEnabled.supplierName.keyword" } }  
}  
}  
},  
"size": 0,  
"\_source": {  
"excludes":   
},  
"stored\_fields": [  
"\*"  
],  
"script\_fields": {  
"timeSpent": {  
"script": {  
"source": "(doc['endDt'].value.millis - doc['beginDt'].value.millis)/1000",  
"lang": "painless"  
}  
},  
"hasResults": {  
"script": {  
"source": "doc['resultsCount'].value \> 0 ? 'Si' : 'No'",  
"lang": "painless"  
}  
}  
},  
"docvalue\_fields": [  
{  
"field": "beginDt",  
"format": "date\_time"  
},  
{  
"field": "checkIn",  
"format": "date\_time"  
},  
{  
"field": "checkOut",  
"format": "date\_time"  
},  
{  
"field": "endDt",  
"format": "date\_time"  
}  
],  
"query": {  
"bool": {  
"must": ,  
"filter": [  
{  
"match\_all": {}  
}  
],  
"should": ,  
"must\_not":   
}  
}  
}

---

<div class="post-metadata">

**Author:** ![wylie](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wylie/32/81794_2.png) [@wylie](https://discuss.elastic.co/u/wylie)\
**Post date:** [December 12, 2019, 4:24pm UTC](https://discuss.elastic.co/t/visualization-for-nested-aggregations/211642/2 "2019-12-12T16:24:45Z")

</div>

Kibana does not aggregate on nested documents: [https://www.elastic.co/guide/en/kibana/current/nested-objects.html](https://www.elastic.co/guide/en/kibana/current/nested-objects.html)

However, if you can build a query directly, you can potentially use the Vega visualization which supports direct querying. [https://www.elastic.co/blog/custom-vega-visualizations-in-kibana](https://www.elastic.co/blog/custom-vega-visualizations-in-kibana)

---

<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:** [January 9, 2020, 4:24pm UTC](https://discuss.elastic.co/t/visualization-for-nested-aggregations/211642/3 "2020-01-09T16:24:54Z")

</div>

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