# Using an aggregation to create histogram in Kibana?

**URL:** https://discuss.elastic.co/t/using-an-aggregation-to-create-histogram-in-kibana/296697
**Category:** Elasticsearch
**Created:** [February 9, 2022, 9:21am UTC](https://discuss.elastic.co/t/using-an-aggregation-to-create-histogram-in-kibana/296697 "2022-02-09T09:21:51Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![saurab](https://avatars.discourse-cdn.com/v4/letter/s/e274bd/32.png) [@saurab](https://discuss.elastic.co/u/saurab)
#### Post date: [February 9, 2022, 9:21am UTC](https://discuss.elastic.co/t/using-an-aggregation-to-create-histogram-in-kibana/296697/1 "2022-02-09T09:21:51Z")

</div>

I have an aggregation on a packetbeat index as follows:

```auto
GET packetbeat-7.16.3-2022.02.07-000001/_search?size=0
{
  "query": {
    "term": {
      "destination.port": 9200
    }
  }, 
  "aggs": {
    "myagg1": {
      "terms": {
        "field": "source.port"
      }, 
      "aggs": {
        "myagg2": {
          "avg": {
            "field": "source.bytes"
          }
        }
      }
    }
  }
}

```

The response is as follows:

```auto
"buckets" : [
        {
          "key" : 49158,
          "doc_count" : 96,
          "myagg2" : {
            "value" : 60275.916666666664
          }
        },
        {
          "key" : 49160,
          "doc_count" : 96,
          "myagg2" : {
            "value" : 59757.5
          }
        },
        {
          "key" : 49170,
          "doc_count" : 96,
          "myagg2" : {
            "value" : 60226.375
          }
        },
        {
          "key" : 49182,
          "doc_count" : 96,
          "myagg2" : {
            "value" : 60236.6875
          }
        },
        {
          "key" : 49184,
          "doc_count" : 96,
          "myagg2" : {
            "value" : 59943.125
          }
        },
        {
          "key" : 49186,
          "doc_count" : 96,
          "myagg2" : {
            "value" : 59683.25
          }
        },
        {
          "key" : 49188,
          "doc_count" : 96,
          "myagg2" : {
            "value" : 60236.6875
          }
        },
        {
          "key" : 49190,
          "doc_count" : 96,
          "myagg2" : {
            "value" : 59978.875
          }
        },
        {
          "key" : 49192,
          "doc_count" : 96,
          "myagg2" : {
            "value" : 59943.125
          }
        }

```

I want to create a histogram using this code in Kibana. How do you do that ? I dont want to use Kibana Query Language, but directly use this aggregation code. Please help!!

---

<div class="post-metadata">

### Author: ![Tomo\_M](https://avatars.discourse-cdn.com/v4/letter/t/848f3c/32.png) [@Tomo\_M](https://discuss.elastic.co/u/Tomo_M)
#### Post date: [February 10, 2022, 3:57pm UTC](https://discuss.elastic.co/t/using-an-aggregation-to-create-histogram-in-kibana/296697/2 "2022-02-10T15:57:14Z")

</div>

Why do you want use the query directly?

It's easy to get such visualization by GUI. Maybe it takes only few minutes. After create visualization by GUI, you can also check the query via `Inspect` page.

---

<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: [March 10, 2022, 3:58pm UTC](https://discuss.elastic.co/t/using-an-aggregation-to-create-histogram-in-kibana/296697/3 "2022-03-10T15:58:11Z")

</div>

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