# Canvas : Is there a way to use range bucket while querying data

**URL:** <https://discuss.elastic.co/t/canvas-is-there-a-way-to-use-range-bucket-while-querying-data/218331>\
**Category:** Kibana\
**Created:** [February 7, 2020, 11:14am UTC](https://discuss.elastic.co/t/canvas-is-there-a-way-to-use-range-bucket-while-querying-data/218331 "2020-02-07T11:14:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sujeet.ssv](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@sujeet.ssv](https://discuss.elastic.co/u/sujeet.ssv)\
**Post date:** [February 7, 2020, 11:14am UTC](https://discuss.elastic.co/t/canvas-is-there-a-way-to-use-range-bucket-while-querying-data/218331/1 "2020-02-07T11:14:06Z")

</div>

Hi

I am novice and still learning how to use canvas feature. I would like to know how to derive bucket aggregation in canvas preferably with some example.  
Something like below , how it can be written in essql?

GET jtlresults-cttd3/\_search  
{  
"aggs" : {  
"time\_ranges" : {  
"range" : {  
"field" : "elapsed",  
"keyed" : true,  
"ranges" : [  
{ "key" : "total", "from" :0 },  
{ "key" : "low", "to" : 2000 },  
{ "key" : "medium", "from" : 2000, "to" : 5000 },  
{ "key" : "high", "from" : 5000 }  
]  
}  
}  
}  
}

---

<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:** [February 12, 2020, 12:58pm UTC](https://discuss.elastic.co/t/canvas-is-there-a-way-to-use-range-bucket-while-querying-data/218331/2 "2020-02-12T12:58:37Z")

</div>

Hi @sujeet.ssv,

yes this is possible by using the `CASE` statement as described here: [https://www.elastic.co/guide/en/elasticsearch/reference/7.6/sql-functions-conditional.html#sql-functions-conditional-case-groupby-custom-buckets](https://www.elastic.co/guide/en/elasticsearch/reference/7.6/sql-functions-conditional.html#sql-functions-conditional-case-groupby-custom-buckets)

```auto
SELECT count(*) AS count,
  CASE WHEN NVL(languages, 0) = 0 THEN 'zero'
    WHEN languages = 1 THEN 'one'
    WHEN languages = 2 THEN 'bilingual'
    WHEN languages = 3 THEN 'trilingual'
    ELSE 'multilingual'
  END as lang_skills
FROM employees
GROUP BY lang_skills
ORDER BY lang_skills;

```

Just put the ranges you want to see in the `WHEN` conditions

---

<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 11, 2020, 12:58pm UTC](https://discuss.elastic.co/t/canvas-is-there-a-way-to-use-range-bucket-while-querying-data/218331/3 "2020-03-11T12:58:52Z")

</div>

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