# Visalization with aggregate and bucket\_script

**URL:** <https://discuss.elastic.co/t/visalization-with-aggregate-and-bucket-script/237301>\
**Category:** Kibana\
**Created:** [June 16, 2020, 12:56pm UTC](https://discuss.elastic.co/t/visalization-with-aggregate-and-bucket-script/237301 "2020-06-16T12:56:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![David70](https://avatars.discourse-cdn.com/v4/letter/d/7ab992/32.png) [@David70](https://discuss.elastic.co/u/David70)\
**Post date:** [June 16, 2020, 12:56pm UTC](https://discuss.elastic.co/t/visalization-with-aggregate-and-bucket-script/237301/1 "2020-06-16T12:56:32Z")

</div>

I'm trying to create a visualization based on the number of days between createdAt and publishedAt. I'm struggling to add the aggregation based on a bucket\_script to Kibana's visualization tab. How do I do it?

Below is my query

```
GET /events-jobs-create/_search
{
  "size": 0,
  "aggs": {
    "company": {
      "terms": {
        "field": "dimensions.company._id.keyword",
        "size": 10
      },
      "aggs": {
        "first_job_create": {
          "min": {
            "field": "createdAt"
          }
        },
        "first_com_create": {
          "max": {
            "field": "publishedAt"
          }
        },
        "time_first_job": {
          "bucket_script": {
            "buckets_path": {
              "fjc": "first_job_create",
              "fcc": "first_com_create"
            },
            "script": {
                            "source": """
							double start = 0;
            double end = 0;
            if(params['fjc'] != null)
            {
              start = params.fjc;
            }
            if(params['fcc'] != null)
            {
              end = params.fcc;
            }
            return (end-start)/1000.0/86400.0;
							"""
            }
          }
        }
      }
    }
  }
}
```

---

<div class="post-metadata">

**Author:** ![flash1293](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/flash1293/32/41227_2.png) [@flash1293](https://discuss.elastic.co/u/flash1293)\
**Post date:** [June 16, 2020, 1:12pm UTC](https://discuss.elastic.co/t/visalization-with-aggregate-and-bucket-script/237301/2 "2020-06-16T13:12:51Z")

</div>

Bucket script is currently not supported in Kibana: [https://github.com/elastic/kibana/issues/4707](https://github.com/elastic/kibana/issues/4707)

You can use the Vega visualization as an escape hatch (it's possible to freely specify your query there), but that means you would need to specify your chart using Vega as well.

---

<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 14, 2020, 1:12pm UTC](https://discuss.elastic.co/t/visalization-with-aggregate-and-bucket-script/237301/3 "2020-07-14T13:12:58Z")

</div>

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