# Kibana visualizations over nested objects

**URL:** <https://discuss.elastic.co/t/kibana-visualizations-over-nested-objects/21996>\
**Category:** Elasticsearch\
**Created:** [February 5, 2015, 5:04pm UTC](https://discuss.elastic.co/t/kibana-visualizations-over-nested-objects/21996 "2015-02-05T17:04:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hayden\_Marchant](https://avatars.discourse-cdn.com/v4/letter/h/7feea3/32.png) [@Hayden\_Marchant](https://discuss.elastic.co/u/Hayden_Marchant)\
**Post date:** [February 5, 2015, 5:04pm UTC](https://discuss.elastic.co/t/kibana-visualizations-over-nested-objects/21996/1 "2015-02-05T17:04:37Z")

</div>

We are experimenting with Kibana for creating dashboards over our index,  
and for some use cases, we need to do aggregations over fields in nested  
objects of our document.

We are having problems with getting visualizations to work for fields over  
nested objects

So in our case, our document represents a user who can have zero or more  
accounts. Each account has a product and account id. The account object  
needs to be defined as a nested object since we want to keep the context of  
each account in order to support queries such as prod='ABC' and  
accid='1234'. Pretty much same reason as the example  
here: [http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/nested-objects.html](http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/nested-objects.html)

THe relevant part of the mapping mapping is here:

"profiles": {  
"\_id": {  
"index": "not\_analyzed"  
},  
"properties": {  
"_account_": {  
"properties": {  
"_product_": {  
"index": "not\_analyzed",  
"type": "string"  
},  
"id\_int": {  
"fielddata": {  
"loading": "lazy",  
"format": "doc\_values"  
},  
"doc\_values": true,  
"type": "long"  
}  
},  
"type": "_nested_"  
},  
"home\_region": {  
"index": "not\_analyzed",  
"type": "string"  
},  
"home\_postal\_code": {  
"index": "not\_analyzed",  
"type": "string"  
},  
"home\_city": {  
"index": "not\_analyzed",  
"type": "string"  
}

```
}

```

}

Our simplest use case is to have a pie chart that is segmented by the  
product field which is part of the nested object.

We would normally submit a query such as :

{  
"size" : 0,  
"query" : {  
"filtered" : {  
"filter" : {  
"match\_all" : { }  
}  
}  
},  
"aggregations" : {  
"product" : {  
"nested" : {  
"path" : "account"  
},  
"aggregations" : {  
"product" : {  
"terms" : {  
"field" : "product",  
"size" : 5,  
"order" : {  
"\_count" : "desc"  
}  
}  
}  
}  
}  
}  
}

From sniffing the network, seems that kibana is doing the following:

"query":{"query\_string":{"query":"_"}},"aggs":{"2":{"terms":{"field":"account.product","size":5,"order":{"\_count":"desc"}}}},"fields":["_","\_source"],"script\_fields":{}

This works great for non-nested objects, but not for nested objects.

Is there a way we can customize the visualization to do this type of  
aggregation? Looks like visState and  
kibanaSavedObjectsMeta.searchSourceJSON in the Edit Visualization Object  
screen might be a good start, though I have not yet been able to follow the  
logic that generates the query string that is submitted to Elasticsearch.

Many thanks in advance,  
Hayden

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/1ff55288-18a1-4ab2-864b-d8d24517921e%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/1ff55288-18a1-4ab2-864b-d8d24517921e%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![pavan\_bkv](https://avatars.discourse-cdn.com/v4/letter/p/6a8cbe/32.png) [@pavan\_bkv](https://discuss.elastic.co/u/pavan_bkv)\
**Post date:** [August 6, 2015, 7:01pm UTC](https://discuss.elastic.co/t/kibana-visualizations-over-nested-objects/21996/2 "2015-08-06T19:01:24Z")

</div>

@Hayden_Marchant, did you find a solution on how to visualize in kibana for nested fields?

---

<div class="post-metadata">

**Author:** ![Hayden\_Marchant](https://avatars.discourse-cdn.com/v4/letter/h/7feea3/32.png) [@Hayden\_Marchant](https://discuss.elastic.co/u/Hayden_Marchant)\
**Post date:** [August 6, 2015, 7:51pm UTC](https://discuss.elastic.co/t/kibana-visualizations-over-nested-objects/21996/3 "2015-08-06T19:51:36Z")

</div>

If I recall correctly, we modeled the nested object twice - once as a  
nested object and once as a flat object. Kibana knew to visualize the flat  
object. Our API needed the nested for complex contextual queries so we kept  
that.

Hope that helps,  
Hayden  
pavan\_bkv [http://discuss.elastic.co/users/pavan\_bkv](http://discuss.elastic.co/users/pavan_bkv) pavan.bkv  
[http://discuss.elastic.co/users/pavan\_bkv](http://discuss.elastic.co/users/pavan_bkv)  
August 6

@Hayden_Marchant [http://discuss.elastic.co/users/hayden\_marchant](http://discuss.elastic.co/users/hayden_marchant), did you  
find a solution on how to visualize in kibana for nested fields?

To respond, reply to this email or visit

> [@Kibana visualizations over nested objects](http://discuss.elastic.co/t/kibana-visualizations-over-nested-objects/21996/2):
>
> @Hayden_Marchant, did you find a solution on how to visualize in kibana for nested fields?

in your browser.

---

<div class="post-metadata">

**Author:** ![pavan\_bkv](https://avatars.discourse-cdn.com/v4/letter/p/6a8cbe/32.png) [@pavan\_bkv](https://discuss.elastic.co/u/pavan_bkv)\
**Post date:** [August 6, 2015, 10:04pm UTC](https://discuss.elastic.co/t/kibana-visualizations-over-nested-objects/21996/4 "2015-08-06T22:04:13Z")

</div>

Wow that's a bummer!

---

<div class="post-metadata">

**Author:** ![ppadovani](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ppadovani/32/8247_2.png) [@ppadovani](https://discuss.elastic.co/u/ppadovani)\
**Post date:** [March 3, 2016, 4:26pm UTC](https://discuss.elastic.co/t/kibana-visualizations-over-nested-objects/21996/5 "2016-03-03T16:26:54Z")

</div>

I have a fork that implements this support, see the discussion on this github issue:

> <https://github.com/elastic/kibana/issues/1084#issuecomment-189199796>

Fork can be found here:  
[https://github.com/homeaway/kibana/tree/fullNestedSupport](https://github.com/homeaway/kibana/tree/fullNestedSupport)

README for the changes:  
[https://github.com/homeaway/kibana/blob/fullNestedSupport/NESTED\_README.md](https://github.com/homeaway/kibana/blob/fullNestedSupport/NESTED_README.md)

---

<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 5, 2017, 11:11pm UTC](https://discuss.elastic.co/t/kibana-visualizations-over-nested-objects/21996/6 "2017-07-05T23:11:33Z")

</div>


