# How Make Select Case When from ElasticSearch

**URL:** <https://discuss.elastic.co/t/how-make-select-case-when-from-elasticsearch/190295>\
**Category:** Elasticsearch\
**Created:** [July 12, 2019, 7:28pm UTC](https://discuss.elastic.co/t/how-make-select-case-when-from-elasticsearch/190295 "2019-07-12T19:28:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![amateur](https://avatars.discourse-cdn.com/v4/letter/a/77aa72/32.png) [@amateur](https://discuss.elastic.co/u/amateur)\
**Post date:** [July 12, 2019, 7:28pm UTC](https://discuss.elastic.co/t/how-make-select-case-when-from-elasticsearch/190295/1 "2019-07-12T19:28:45Z")

</div>

Hello,

I have an integration between Grafana and SQL Server, but I want to change to ElasticSearch, but I need to know how to do this query in Grafana with for ElasticSeacrh:

"SELECT  
dbo.access.time,  
case when dbo.access.time\> 45000 or dbo.access.cod\_status = 500 then 0 else 100 end as 'Uptime'  
From  
dbo.access  
WHERE  
$ \_\_ timeFilter (dbo.access.time) "

How I do it so that it works for me in ElasticSearch assuming it has the same fields.

Please your help.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [July 13, 2019, 6:26am UTC](https://discuss.elastic.co/t/how-make-select-case-when-from-elasticsearch/190295/2 "2019-07-13T06:26:52Z")

</div>

This could help: [https://www.elastic.co/guide/en/elasticsearch/reference/current/sql-functions-conditional.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/sql-functions-conditional.html)

If you use then [https://www.elastic.co/guide/en/elasticsearch/reference/current/sql-translate.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/sql-translate.html) you can see what is generated behind the scene.

---

<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:** [August 10, 2019, 6:26am UTC](https://discuss.elastic.co/t/how-make-select-case-when-from-elasticsearch/190295/3 "2019-08-10T06:26:53Z")

</div>

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