# How to extract a function from Kibana source code?

**URL:** <https://discuss.elastic.co/t/how-to-extract-a-function-from-kibana-source-code/288996>\
**Category:** Kibana\
**Created:** [November 11, 2021, 2:13pm UTC](https://discuss.elastic.co/t/how-to-extract-a-function-from-kibana-source-code/288996 "2021-11-11T14:13:27Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sandra\_Schlichting](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sandra_schlichting/32/84122_2.png) [@Sandra\_Schlichting](https://discuss.elastic.co/u/Sandra_Schlichting)\
**Post date:** [November 11, 2021, 2:13pm UTC](https://discuss.elastic.co/t/how-to-extract-a-function-from-kibana-source-code/288996/1 "2021-11-11T14:13:27Z")

</div>

Dear all =)

I would like to be able to convert KQL to Lucene in my NodeJS application that uses the Kibana API to create rules.

In [this](https://github.com/elastic/kibana/tree/8a83955650432e977d1d75adaab0aa4638cefe8a/packages/kbn-es-query#kuery) I see `fromExpression(expression)` and `toElasticsearchQuery(node, indexPattern)` does exactly that =)

TypeScript is new to me, and also working with so large code bases as Kibana, so I am compeltely blank on where and how to extract the files I would need and how to compile them to ES6+ afterwards.

Is there a Kibana developer out there that can help me with this? =)

Hugs,  
Sandra =)

---

<div class="post-metadata">

**Author:** ![sebastien](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sebastien/32/36119_2.png) [@sebastien](https://discuss.elastic.co/u/sebastien)\
**Post date:** [November 11, 2021, 5:05pm UTC](https://discuss.elastic.co/t/how-to-extract-a-function-from-kibana-source-code/288996/2 "2021-11-11T17:05:56Z")

</div>

Hi @Sandra_Schlichting

If you are new to Typescript I would recommend cloning [a starter like this one](https://github.com/stemmlerjs/simple-typescript-starter) to get you started.

Then you should be able to have the "kbn-es-query" folder in the "src" folder of your project. **But** this might be a license infringement so I would suggest that you write first an email to [elastic\_license@elastic.co](mailto:elastic_license@elastic.co) to verify that what you would like to do is OK under our license terms.

Thank you  
Sébastien

---

<div class="post-metadata">

**Author:** ![Sandra\_Schlichting](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sandra_schlichting/32/84122_2.png) [@Sandra\_Schlichting](https://discuss.elastic.co/u/Sandra_Schlichting)\
**Post date:** [November 11, 2021, 9:19pm UTC](https://discuss.elastic.co/t/how-to-extract-a-function-from-kibana-source-code/288996/3 "2021-11-11T21:19:20Z")

</div>

Dear Sébastien

Thanks a lot for the kick start =)

Good point about the license. I'll have my boss contact [elastic\_license@elastic.co](mailto:elastic_license@elastic.co) before I proceed on this.

Hugs,  
Sandra =)

---

<div class="post-metadata">

**Author:** ![Sandra\_Schlichting](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sandra_schlichting/32/84122_2.png) [@Sandra\_Schlichting](https://discuss.elastic.co/u/Sandra_Schlichting)\
**Post date:** [November 16, 2021, 12:56pm UTC](https://discuss.elastic.co/t/how-to-extract-a-function-from-kibana-source-code/288996/4 "2021-11-16T12:56:44Z")

</div>

Dear Sébastien =)

I have now looked at the licenses, and there seams to be 3 depending on which files one would like to use. My boss proposes I get an exact list of the files I need before contacting [elastic\_license@elastic.co](mailto:elastic_license@elastic.co) .

So my current thinking is just to get it to compile, but I get the below errors. Can you figure out what I am doing wrong?

```auto
git clone https://github.com/stemmlerjs/simple-typescript-starter
cd simple-typescript-starter/
npm install
cp -a ~/kibana/packages/kbn-es-query/ src/
npm install @types/lodash
npm install @kbn/utility-types
npm run build

```

gives me a long list of errors similar to

```auto
Cannot find module '@kbn/utility-types'

```

full output [here](https://pastebin.com/mcv2fLNm)

I imagine I somehow have to build `@kbn/utility-types` first?

Hugs,  
Sandra =)

---

<div class="post-metadata">

**Author:** ![sebastien](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sebastien/32/36119_2.png) [@sebastien](https://discuss.elastic.co/u/sebastien)\
**Post date:** [November 18, 2021, 12:07pm UTC](https://discuss.elastic.co/t/how-to-extract-a-function-from-kibana-source-code/288996/5 "2021-11-18T12:07:21Z")

</div>

Hi @Sandra_Schlichting

Yes indeed you will need to bring over all the other package dependencies. And probably change the imports from absolute imports (e.g. `import { <something> } from '@kbn/utility-types'`) to relative imports (`import { <something> } from '../../@kbn-utility-types'`)

Another option is to compile the packages and place them in the `node_modules` folder. But that has its own part of difficulties.

Good luck!  
Sébastien

---

<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:** [December 16, 2021, 12:08pm UTC](https://discuss.elastic.co/t/how-to-extract-a-function-from-kibana-source-code/288996/6 "2021-12-16T12:08:00Z")

</div>

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