# Table aggregation

**URL:** <https://discuss.elastic.co/t/table-aggregation/370577>\
**Category:** Kibana\
**Created:** [November 14, 2024, 6:59pm UTC](https://discuss.elastic.co/t/table-aggregation/370577 "2024-11-14T18:59:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nnikushkin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nnikushkin/32/122950_2.png) [@nnikushkin](https://discuss.elastic.co/u/nnikushkin)\
**Post date:** [November 14, 2024, 6:59pm UTC](https://discuss.elastic.co/t/table-aggregation/370577/1 "2024-11-14T18:59:42Z")

</div>

Hello!

Here is the initial data:

```auto
POST someindex/_doc
{
  "name": "Amsterdam",
  "documents": {
    "locations": [
      {
        "category": "aaa",
        "url": "https://aaa1.com"
      },
      {
        "category": "bbb",
        "url": "https://bbb1.com"
      },
      {
        "category": "aaa",
        "url": "https://aaa11.com"
      },
      {
        "category": "ccc",
        "url": "https://ccc1.com"
      }
      ]
  }
}
POST someindex/_doc
{
  "naam": "Hague",
  "documents": {
    "locations": [
      {
        "category": "ccc",
        "url": "https://ccc2.com"
      }
      ]
  }
}
POST someindex/_doc
{
  "naam": "Utrecht",
  "documents": {
    "locations": [
      {
        "category": "aaa",
        "url": "https://aaa3.com"
      },
      {
        "category": "ddd",
        "url": "https://ddd3.com"
      }
      ]
  }
}

```

I want to show how many categories every city has

So, basically I would like to build a table like this:

```auto
	              aaa bbb ccc ddd
Amsterdam 2 1 1 0
Hague 0 0 1 0
Utrecht 1 0 0 1

```

For now, I was able to build a table representing if the specific category is present for the city, but cannot make it display the number of categories as I wish:

```auto
	              aaa bbb ccc ddd
Amsterdam 1 1 1 0
Hague 0 0 1 0
Utrecht 1 0 0 1

```

However, if I switch the metrics field from "count(records)" to "count(documents.locations.category)" Kibana visualize it in the following way:

```auto
	              aaa bbb ccc ddd
Amsterdam 3 3 3 0
Hague 0 0 1 0
Utrecht 2 0 0 2

```

I tried switching to explicit nested type in mapping but then Kibana does not allow to build me a visualization at all

So, is there a solution to my problem or it cannot be done?

Kibana is **8.15.3**

Thank you!

---

<div class="post-metadata">

**Author:** ![Marta\_Bondyra](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marta_bondyra/32/102122_2.png) [@Marta\_Bondyra](https://discuss.elastic.co/u/Marta_Bondyra)\
**Post date:** [November 15, 2024, 2:04pm UTC](https://discuss.elastic.co/t/table-aggregation/370577/2 "2024-11-15T14:04:53Z")

</div>

Hi Nikita, I'd say this qualifies under the realm of nested fields problems. Unfortunately, nested fields are not well supported at this moment. We have an issue for it: [Nested field support · Issue #1084 · elastic/kibana · GitHub](https://github.com/elastic/kibana/issues/1084#issuecomment-2052107011)
