# How to visualize a query in kibana

**URL:** https://discuss.elastic.co/t/how-to-visualize-a-query-in-kibana/293019
**Category:** Kibana
**Tags:** painless
**Created:** [December 28, 2021, 6:47am UTC](https://discuss.elastic.co/t/how-to-visualize-a-query-in-kibana/293019 "2021-12-28T06:47:08Z")
**Posts on this page:** 3
**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 28, 2021, 6:47am UTC](https://discuss.elastic.co/t/how-to-visualize-a-query-in-kibana/293019/1 "2021-12-28T06:47:08Z")

</div>

Hello! need help with visualizing this query in kibana:

```auto
{
  "size": 0,
  "aggs": {
    "orders_per_day": {
      "terms": {
        "script": {
          "lang": "painless",
          "source": "doc['ctime'].value.dayOfWeek"
        }
      },
      "aggs": {
        "avg_per_hour": {
          "bucket_script": {
            "buckets_path": {
              "count": "_count"
            },
            "script": "params.count / 24"
          }
        }
      }
    }
  }
}

```

my log

```auto
{
        "_index" : "test",
        "_type" : "_doc",
        "_id" : "09-20-00-246697_test.log",
        "_version" : 8,
        "_score" : null,
        "_source" : {
          "hash" : {
            "sha1" : "ded3628a07efdce5cb972d24020852bb16e35a48"
          },
          "filename" : "09-20-00-246697_test.log",
          "ctime" : "2021-12-28T06:20:00.246Z",
          "@version" : "1",
          "tags" : [
            "GT",
            "beats_input_raw_event"
          ]

```

---

<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: [December 29, 2021, 6:54pm UTC](https://discuss.elastic.co/t/how-to-visualize-a-query-in-kibana/293019/2 "2021-12-29T18:54:51Z")

</div>

Hi there -- Bucket script aggregations are only available in Kibana when using TSVB visualizations. These two forum posts give some nice examples of how to use it, hopefully it helps point you in the right direction:

> [@Weighted Average in a DataTable of Kibana](https://discuss.elastic.co/t/weighted-average-in-a-datatable-of-kibana/185909/2):
>
> Hi Henrique, I think solving your problem will be a two-step process. You'll need to create a per-document field for cost \* volume, e.g. a field called volumeCost. You could create this field two ways, either by [reindexing your data](https://www.elastic.co/guide/en/elasticsearch/reference/6.0/docs-reindex.html#docs-reindex) and adding the field with a Painless script, or by creating a [scripted field](https://www.elastic.co/guide/en/kibana/current/scripted-fields.html) that calculates this value on the fly. The first option is a little more performant when querying your data but the second option might be easier. I think you can create a Timeseries v…

> [@Visualize a value calculated from the per-bucket sum of one field divided by the per-bucket sum of another?](https://discuss.elastic.co/t/visualize-a-value-calculated-from-the-per-bucket-sum-of-one-field-divided-by-the-per-bucket-sum-of-another/254359):
>
> I have data in JSON Lines format that contains statistics about the tasks performed by a system over an interval of time. (The specific definition of "task" here is not important.) Each line of JSON Lines contains, among other fields: A time stamp representing the start of the time interval The total number of tasks in that interval The total response time of those tasks For example, here is a snippet of one of the lines: { "Start Interval": "2019-08-31T15:45:00.000Z", "#Tasks": 6, …

---

<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 26, 2022, 6:54pm UTC](https://discuss.elastic.co/t/how-to-visualize-a-query-in-kibana/293019/3 "2022-01-26T18:54:55Z")

</div>

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