# Outermost aggregation in Visual Builder cannot be (term) Bucket

**URL:** https://discuss.elastic.co/t/outermost-aggregation-in-visual-builder-cannot-be-term-bucket/151677
**Category:** Kibana
**Created:** [October 9, 2018, 3:47pm UTC](https://discuss.elastic.co/t/outermost-aggregation-in-visual-builder-cannot-be-term-bucket/151677 "2018-10-09T15:47:04Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![iamthealex](https://avatars.discourse-cdn.com/v4/letter/i/e9c0ed/32.png) [@iamthealex](https://discuss.elastic.co/u/iamthealex)
#### Post date: [October 9, 2018, 3:47pm UTC](https://discuss.elastic.co/t/outermost-aggregation-in-visual-builder-cannot-be-term-bucket/151677/1 "2018-10-09T15:47:04Z")

</div>

Is there a way to start with a bucket filter in Visual Builder?  
I want to do a bucket aggregation and have the child aggs of the outer bucket generate the time series of values.

Something like this query which works just fine in the dev console:

```
  "aggs": {  
    "series": { 
      "date_histogram": { "field": "@timestamp", "interval": "hour" } ,
      "aggs": {
        "bucket_by_host": { 
          "terms": { "field": "host" },
          "aggs": {
            "used" : {"sum": { "field": "server-ram-b" } },
            "installed" : {"max": { "field": "host-ram-b" } },
            "ratio" : { "bucket_script": { "buckets_path": { "used": "used", "installed": "installed" }, "script": " (params.used / params.installed) " } }
          }
        },
       "total-ratio" : { "avg_bucket": { "buckets_path": "bucket_by_host>ratio " } }     
      }
    }
  }
}
```

---

<div class="post-metadata">

### Author: ![Marius\_Dragomir](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marius_dragomir/32/42087_2.png) [@Marius\_Dragomir](https://discuss.elastic.co/u/Marius_Dragomir)
#### Post date: [October 11, 2018, 1:23pm UTC](https://discuss.elastic.co/t/outermost-aggregation-in-visual-builder-cannot-be-term-bucket/151677/2 "2018-10-11T13:23:04Z")

</div>

Hello,  
Bucket script parent pipeline aggregation is available in TSVB, so you could build this using that. See an example in the image below:

 ![bucketscript](https://us1.discourse-cdn.com/elastic/original/3X/8/f/8fcd5c79cd84864f80a560418a5272bb19906603.png)

---

<div class="post-metadata">

### Author: ![iamthealex](https://avatars.discourse-cdn.com/v4/letter/i/e9c0ed/32.png) [@iamthealex](https://discuss.elastic.co/u/iamthealex)
#### Post date: [October 11, 2018, 2:48pm UTC](https://discuss.elastic.co/t/outermost-aggregation-in-visual-builder-cannot-be-term-bucket/151677/3 "2018-10-11T14:48:41Z")

</div>

If you can show me how to bucket by terms, then I will be happy.  
I should probably retitle this issue to say that, but instead I've recently been looking at Vega Kibana plugin.  
I had found the above already, but the larger ask is to be able to start with a term bucket.  
I think I can use any query I want and point Vega at the results.  
So, I'm moving to Vega for visualizing the responses from arbitrarily complicated queries.

---

<div class="post-metadata">

### Author: ![iamthealex](https://avatars.discourse-cdn.com/v4/letter/i/e9c0ed/32.png) [@iamthealex](https://discuss.elastic.co/u/iamthealex)
#### Post date: [October 12, 2018, 8:48pm UTC](https://discuss.elastic.co/t/outermost-aggregation-in-visual-builder-cannot-be-term-bucket/151677/4 "2018-10-12T20:48:25Z")

</div>

Elastic support confirmed that it is not currently possible to start with a term bucket in Visual Builder.

---

<div class="post-metadata">

### Author: ![Marius\_Dragomir](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marius_dragomir/32/42087_2.png) [@Marius\_Dragomir](https://discuss.elastic.co/u/Marius_Dragomir)
#### Post date: [October 14, 2018, 2:34pm UTC](https://discuss.elastic.co/t/outermost-aggregation-in-visual-builder-cannot-be-term-bucket/151677/5 "2018-10-14T14:34:57Z")

</div>

If you want to switch to Vega, feel free to open another issue so that other people notice it, that have better knowledge about it than me.

---

<div class="post-metadata">

### Author: ![iamthealex](https://avatars.discourse-cdn.com/v4/letter/i/e9c0ed/32.png) [@iamthealex](https://discuss.elastic.co/u/iamthealex)
#### Post date: [October 23, 2018, 7:05pm UTC](https://discuss.elastic.co/t/outermost-aggregation-in-visual-builder-cannot-be-term-bucket/151677/6 "2018-10-23T19:05:21Z")

</div>

And the problem with Vega is that I don't think it pays attention to Kibana filters.

---

<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: [November 20, 2018, 7:07pm UTC](https://discuss.elastic.co/t/outermost-aggregation-in-visual-builder-cannot-be-term-bucket/151677/7 "2018-11-20T19:07:24Z")

</div>

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