# Kibana - Visualisation aggregation on Nested Object Issue

**URL:** https://discuss.elastic.co/t/kibana-visualisation-aggregation-on-nested-object-issue/233097
**Category:** Kibana
**Created:** [May 18, 2020, 11:33am UTC](https://discuss.elastic.co/t/kibana-visualisation-aggregation-on-nested-object-issue/233097 "2020-05-18T11:33:45Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![charlz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/charlz/32/70782_2.png) [@charlz](https://discuss.elastic.co/u/charlz)
#### Post date: [May 18, 2020, 11:33am UTC](https://discuss.elastic.co/t/kibana-visualisation-aggregation-on-nested-object-issue/233097/1 "2020-05-18T11:33:45Z")

</div>

On creating Visualisation Aggregation of sum on property 'item.count' facing issue  
grouping on quote.created\_at  
**Result**  
Date ------------Count  
2020-05-10 ----- 1  
2020-03-05 ----- 2

```auto
 {
    "id":50,
    "created_at":"2019-05-10T00:00:00",
     "item":[
          {"id":5,"count":1,"created_at":"2020-03-05T00:00:00"},
          {"id":11, "count":1,"created_at":"2020-03-05T00:00:00"}
      ]
   },
  {
      "id":65,
       "created_at":"2019-05-01T00:00:00",
        "item":[
             {"id":15, "count":1,"created_at":"2020-05-10T00:00:00"},
             {"id":19, "count":1,"created_at":"2020-03-05T00:00:00"}
         ]
  } 

```

**Expected Result**  
Date ------------Count  
2020-05-10 ----- 1  
2020-03-05 ----- 3

---

<div class="post-metadata">

### Author: ![lukeelmers](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukeelmers/32/35230_2.png) [@lukeelmers](https://discuss.elastic.co/u/lukeelmers)
#### Post date: [May 18, 2020, 10:32pm UTC](https://discuss.elastic.co/t/kibana-visualisation-aggregation-on-nested-object-issue/233097/2 "2020-05-18T22:32:03Z")

</div>

Hi @charlz,

Kibana visualizations do not currently support querying on nested fields, however [there is a Github issue](https://github.com/elastic/kibana/issues/1084#issuecomment-585178079) tracking the overall progress of nested fields support if you'd like to follow along.

As of 7.6 you can use nested fields in Discover, Index Patterns, KQL, & the Filter Bar, but visualizations are not enabled yet. There's also a [dedicated issue](https://github.com/elastic/kibana/issues/58175) tracking progress in visualize specifically.

---

<div class="post-metadata">

### Author: ![charlz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/charlz/32/70782_2.png) [@charlz](https://discuss.elastic.co/u/charlz)
#### Post date: [May 19, 2020, 6:12am UTC](https://discuss.elastic.co/t/kibana-visualisation-aggregation-on-nested-object-issue/233097/3 "2020-05-19T06:12:39Z")

</div>

Hi @lukeelmers

Yes, Nested objected is not supported currently, since I have not mapped the field ('item') as Nested Objected. the fields are available in the Kibana visualisations my questions is aggregation (sum) on the field (which of nested) must provide the result similar field (integer) since the field is available in visualisations.

---

<div class="post-metadata">

### Author: ![lukeelmers](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukeelmers/32/35230_2.png) [@lukeelmers](https://discuss.elastic.co/u/lukeelmers)
#### Post date: [May 20, 2020, 2:36pm UTC](https://discuss.elastic.co/t/kibana-visualisation-aggregation-on-nested-object-issue/233097/4 "2020-05-20T14:36:48Z")

</div>

> the fields are available in the Kibana visualisations my questions is aggregation (sum) on the field (which of nested) must provide the result similar field (integer) since the field is available in visualisations.

I'm not 100% sure I understand this question, so apologies if there is something I'm overlooking. But visualizations in Kibana don't aggregate on nested fields like that, regardless of how you set your mappings -- if you want to run aggregations on the data in the `items` list, you aren't going to get the results you are looking for.

My recommendation would be to restructure your data so that each `item` is a separate document which references the parent ID:

```auto
{"id":15, "count":1, "created_at":"2020-05-10T00:00:00", "parent_id": 65},
{"id":19, "count":1, "created_at":"2020-03-05T00:00:00", "parent_id": 65},
{"id":11, "count":1, "created_at":"2020-03-05T00:00:00", "parent_id": 50},
{"id":5, "count":1, "created_at":"2020-03-05T00:00:00", "parent_id": 50}

```

Then doing the same sum aggregation should return the expected results. This will also give you greater long-term flexibility in your visualizations.

---

<div class="post-metadata">

### Author: ![charlz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/charlz/32/70782_2.png) [@charlz](https://discuss.elastic.co/u/charlz)
#### Post date: [May 21, 2020, 6:25am UTC](https://discuss.elastic.co/t/kibana-visualisation-aggregation-on-nested-object-issue/233097/5 "2020-05-21T06:25:35Z")

</div>

@lukeelmers  
Thanks, Is it your recommendation to have restructure the document with "join" (parent-child) in single Index?

I would also like to have data structure to relation kind-of document instead of single document,  
Could you give more in-sight, since I'm using Elastic-search version 7.2 which does not have mappings. How does Routing works?  
I was checking into [https://www.elastic.co/guide/en/elasticsearch/reference/7.2/parent-join.html](https://www.elastic.co/guide/en/elasticsearch/reference/7.2/parent-join.html) for reference.  
My use case does suit for "Join" the one-to-many relationship where one entity significantly outnumbers the other entity.

But does Kibana support Parent/Child? If not what would be other options?

Because in my use case few filters for Kibana Dashboard of child (item) are based on the parent (root), eg (properties - state, type, active)

Count number of Child Item filtered by parent state=1 and active =1 and few other scenarios

```auto
 {
    "id":50,"created_at":"2019-05-10T00:00:00","state":1,"type":"Blue","active":1,
     "item":[
          {"id":5,"count":1,"created_at":"2020-03-05T00:00:00"},
          {"id":11, "count":1,"created_at":"2020-03-05T00:00:00"}
      ]
   },
  {
      "id":65,"created_at":"2019-05-01T00:00:00","state":3,"type":"Green","active":0,
        "item":[
             {"id":15, "count":1,"created_at":"2020-05-10T00:00:00"},
             {"id":19, "count":1,"created_at":"2020-03-05T00:00:00"}
         ]
  }

```

After restructuring the doc

```auto
{"id":50,"created_at":"2019-05-10T00:00:00","state":1,"type":"Blue","active":1},
{"id":65,"created_at":"2019-05-01T00:00:00","state":3,"type":"Green","active":0},
{"id":5,"count":1,"created_at":"2020-03-05T00:00:00","parent_id":50},
{"id":11, "count":1,"created_at":"2020-03-05T00:00:00","parent_id":50},
{"id":15, "count":1,"created_at":"2020-05-10T00:00:00","parent_id":65},
{"id":19, "count":1,"created_at":"2020-03-05T00:00:00","parent_id":65}

```

---

<div class="post-metadata">

### Author: ![charlz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/charlz/32/70782_2.png) [@charlz](https://discuss.elastic.co/u/charlz)
#### Post date: [June 4, 2020, 1:07pm UTC](https://discuss.elastic.co/t/kibana-visualisation-aggregation-on-nested-object-issue/233097/6 "2020-06-04T13:07:03Z")

</div>

can anyone guide me on this scenario, right way of structuring the data?

---

<div class="post-metadata">

### Author: ![charlz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/charlz/32/70782_2.png) [@charlz](https://discuss.elastic.co/u/charlz)
#### Post date: [June 23, 2020, 6:00am UTC](https://discuss.elastic.co/t/kibana-visualisation-aggregation-on-nested-object-issue/233097/7 "2020-06-23T06:00:21Z")

</div>

can anyone guide me on this scenario, right way of structuring the data?

---

<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 21, 2020, 6:00am UTC](https://discuss.elastic.co/t/kibana-visualisation-aggregation-on-nested-object-issue/233097/8 "2020-07-21T06:00:24Z")

</div>

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