# Kibana Query Language (KQL) library to convert KQL to ElasticSearch Query

**URL:** https://discuss.elastic.co/t/kibana-query-language-kql-library-to-convert-kql-to-elasticsearch-query/276722
**Category:** Kibana
**Created:** [June 23, 2021, 5:58am UTC](https://discuss.elastic.co/t/kibana-query-language-kql-library-to-convert-kql-to-elasticsearch-query/276722 "2021-06-23T05:58:24Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Saurabh\_Kumar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/saurabh_kumar/32/90671_2.png) [@Saurabh\_Kumar](https://discuss.elastic.co/u/Saurabh_Kumar)
#### Post date: [June 23, 2021, 5:58am UTC](https://discuss.elastic.co/t/kibana-query-language-kql-library-to-convert-kql-to-elasticsearch-query/276722/1 "2021-06-23T05:58:25Z")

</div>

Hello Experts,

I am trying to create DataQueryInterface (API Layer) which is independent from backend Datasource. Current I am thinking to have ElasticSearch as my datasource but in future if I want to move out of ElasticSearch, that should not break my API layer. For that I was looking at exposing KQL as my DataQueryInterface (API Layer). That way I would have deserialization code from KQL and if I want to move out of ElasticSearch in future, I can use Kibana's deserialization code to populate my POJOs and then form new query to new database.  
Could someone please help pointing me to the exact code for this?

Thanks,  
Saurabh

---

<div class="post-metadata">

### Author: ![Saurabh\_Kumar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/saurabh_kumar/32/90671_2.png) [@Saurabh\_Kumar](https://discuss.elastic.co/u/Saurabh_Kumar)
#### Post date: [June 25, 2021, 9:49am UTC](https://discuss.elastic.co/t/kibana-query-language-kql-library-to-convert-kql-to-elasticsearch-query/276722/2 "2021-06-25T09:49:26Z")

</div>

Hello Experts,

Could someone help on this please?

---

<div class="post-metadata">

### Author: ![Saurabh\_Kumar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/saurabh_kumar/32/90671_2.png) [@Saurabh\_Kumar](https://discuss.elastic.co/u/Saurabh_Kumar)
#### Post date: [June 29, 2021, 8:05am UTC](https://discuss.elastic.co/t/kibana-query-language-kql-library-to-convert-kql-to-elasticsearch-query/276722/3 "2021-06-29T08:05:21Z")

</div>

Hello Experts,

Could someone please help on this ?

---

<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 29, 2021, 8:31am UTC](https://discuss.elastic.co/t/kibana-query-language-kql-library-to-convert-kql-to-elasticsearch-query/276722/4 "2021-06-29T08:31:02Z")

</div>

The magical function turning a kql string into Elasticsearch query DSL (note: this isn't a full query, it's just part of it) can be found here: [kibana/from\_kuery.ts at 77fe1c10870a3fb72eb3643d373c3ba0e7405a1a · elastic/kibana · GitHub](https://github.com/elastic/kibana/blob/77fe1c10870a3fb72eb3643d373c3ba0e7405a1a/src/plugins/data/common/es_query/es_query/from_kuery.ts#L13)

However it's not easy to use outside of Kibana.

---

<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 27, 2021, 8:31am UTC](https://discuss.elastic.co/t/kibana-query-language-kql-library-to-convert-kql-to-elasticsearch-query/276722/5 "2021-07-27T08:31:35Z")

</div>

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