# How to visualize this query in kibana?

**URL:** <https://discuss.elastic.co/t/how-to-visualize-this-query-in-kibana/292943>\
**Category:** Kibana\
**Tags:** painless\
**Created:** [December 26, 2021, 8:38pm UTC](https://discuss.elastic.co/t/how-to-visualize-this-query-in-kibana/292943 "2021-12-26T20:38:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cva](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cva/32/85514_2.png) [@cva](https://discuss.elastic.co/u/cva)\
**Post date:** [December 26, 2021, 8:38pm UTC](https://discuss.elastic.co/t/how-to-visualize-this-query-in-kibana/292943/1 "2021-12-26T20:38:33Z")

</div>

How to visualize this query in kibana?

```auto
POST /teletrain/_search
{
  "size": 0,
  "aggs": {
    "orders_per_hour_of_day": {
      "terms": {
        "script": {
          "lang": "painless",
          "source": "doc['ctime'].value.getHour()"
        },
        "size": 24
      },
      "aggs": {
        "total_orders_per_day_of_week": {
          "terms": {
            "script": {
              "lang": "painless",
              "source": "doc['ctime'].value.getDayOfWeekEnum()"
            }
          },
          "aggs": {
            "number_of_weeks": {
              "date_histogram": {
                "field": "ctime",
                "calendar_interval": "week"
              }
            },
            "average_orders_per_hour_day_of_week": {
              "bucket_script": {
                "buckets_path": {
                  "doc_count": "_count",
                  "number_of_weeks": "number_of_weeks._bucket_count"
                },
                "script": "params.doc_count / params.number_of_weeks"
              }
            }
          }
        }
      }
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![bhavyarm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bhavyarm/32/22392_2.png) [@bhavyarm](https://discuss.elastic.co/u/bhavyarm)\
**Post date:** [December 31, 2021, 1:50pm UTC](https://discuss.elastic.co/t/how-to-visualize-this-query-in-kibana/292943/2 "2021-12-31T13:50:01Z")

</div>

Hello,

How did you get this query?

Looks like [TSVB | Kibana Guide [master] | Elastic](https://www.elastic.co/guide/en/kibana/master/tsvb.html) will help you?

Thanks,  
Bhavya

---

<div class="post-metadata">

**Author:** ![cva](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cva/32/85514_2.png) [@cva](https://discuss.elastic.co/u/cva)\
**Post date:** [January 2, 2022, 8:03pm UTC](https://discuss.elastic.co/t/how-to-visualize-this-query-in-kibana/292943/3 "2022-01-02T20:03:02Z")

</div>

Thanks for the information. But I am having difficulties with this part of the request

```auto
{
  "size": 0,
  "aggs": {
    "orders_per_hour_of_day": {
      "terms": {
        "script": {
          "lang": "painless",
          "source": "doc['ctime'].value.getHour()"
        }

```

, I would be very grateful for your help in deciding how to submit this part of the request to TSVB

---

<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 30, 2022, 8:03pm UTC](https://discuss.elastic.co/t/how-to-visualize-this-query-in-kibana/292943/4 "2022-01-30T20:03:28Z")

</div>

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