# Make ES Queries from my Custom Kibana Plugin

**URL:** <https://discuss.elastic.co/t/make-es-queries-from-my-custom-kibana-plugin/261416>\
**Category:** Kibana\
**Created:** [January 18, 2021, 11:25am UTC](https://discuss.elastic.co/t/make-es-queries-from-my-custom-kibana-plugin/261416 "2021-01-18T11:25:29Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![xenon-xenon](https://avatars.discourse-cdn.com/v4/letter/x/ccd318/32.png) [@xenon-xenon](https://discuss.elastic.co/u/xenon-xenon)\
**Post date:** [January 18, 2021, 11:25am UTC](https://discuss.elastic.co/t/make-es-queries-from-my-custom-kibana-plugin/261416/1 "2021-01-18T11:25:29Z")

</div>

I'm looking for best way of create ES queries from my plugin like : without ES **authentication** stuff  
I mean **best and recommended** way

---

<div class="post-metadata">

**Author:** ![markov00](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/markov00/32/33316_2.png) [@markov00](https://discuss.elastic.co/u/markov00)\
**Post date:** [January 18, 2021, 12:11pm UTC](https://discuss.elastic.co/t/make-es-queries-from-my-custom-kibana-plugin/261416/2 "2021-01-18T12:11:19Z")

</div>

Hi, the best way to do that without thinking about authentication etc is to use the provided Data plugin service, see [https://github.com/elastic/kibana/tree/7.10/src/plugins/data](https://github.com/elastic/kibana/tree/7.10/src/plugins/data) for the documentation

---

<div class="post-metadata">

**Author:** ![xenon-xenon](https://avatars.discourse-cdn.com/v4/letter/x/ccd318/32.png) [@xenon-xenon](https://discuss.elastic.co/u/xenon-xenon)\
**Post date:** [January 18, 2021, 5:57pm UTC](https://discuss.elastic.co/t/make-es-queries-from-my-custom-kibana-plugin/261416/3 "2021-01-18T17:57:26Z")

</div>

I am new in plugin development , how can I use that is it module ? , should I import it ?

---

<div class="post-metadata">

**Author:** ![markov00](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/markov00/32/33316_2.png) [@markov00](https://discuss.elastic.co/u/markov00)\
**Post date:** [January 18, 2021, 6:33pm UTC](https://discuss.elastic.co/t/make-es-queries-from-my-custom-kibana-plugin/261416/4 "2021-01-18T18:33:43Z")

</div>

Hi, so I need to check if we have an upgraded version of the documentation for plugins, their structure was changed not so long ago and is not fully documented.  
In the meantime, you can take a look at the examples that exist here: [https://github.com/elastic/kibana/tree/master/examples](https://github.com/elastic/kibana/tree/master/examples)  
in particular the state containers example [https://github.com/elastic/kibana/tree/master/examples/state\_containers\_examples](https://github.com/elastic/kibana/tree/master/examples/state_containers_examples) provides an example on how to use the data plugin

---

<div class="post-metadata">

**Author:** ![markov00](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/markov00/32/33316_2.png) [@markov00](https://discuss.elastic.co/u/markov00)\
**Post date:** [January 18, 2021, 6:36pm UTC](https://discuss.elastic.co/t/make-es-queries-from-my-custom-kibana-plugin/261416/5 "2021-01-18T18:36:58Z")

</div>

The official documentation seems to be updated: [https://www.elastic.co/guide/en/kibana/current/kibana-platform-plugin-api.html](https://www.elastic.co/guide/en/kibana/current/kibana-platform-plugin-api.html) but I don't see there an example of the usage for the data plugin  
You have basically need to declare your dependency with the `data` plugin in your `kibana.json` manifest file and that you can import it in your application and use it

---

<div class="post-metadata">

**Author:** ![xenon-xenon](https://avatars.discourse-cdn.com/v4/letter/x/ccd318/32.png) [@xenon-xenon](https://discuss.elastic.co/u/xenon-xenon)\
**Post date:** [January 19, 2021, 1:44pm UTC](https://discuss.elastic.co/t/make-es-queries-from-my-custom-kibana-plugin/261416/6 "2021-01-19T13:44:43Z")

</div>

Is there any documentation for using data plugin service I added **data** into my kibana.json file as a requiredPlugins.

---

<div class="post-metadata">

**Author:** ![lukas](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukas/32/6812_2.png) [@lukas](https://discuss.elastic.co/u/lukas)\
**Post date:** [January 19, 2021, 4:27pm UTC](https://discuss.elastic.co/t/make-es-queries-from-my-custom-kibana-plugin/261416/7 "2021-01-19T16:27:05Z")

</div>

Your plugin's dependencies are passed as the second argument to `start` and `stop`:

```auto
export class MyPlugin implements Plugin {
  constructor(initializerContext: PluginInitializerContext) {}

  public setup(core: CoreSetup, { data }) {
    // here you can access things inside data from DataPluginSetup (see src/plugins/data/server/plugin.ts)
  }

  public start(core: CoreStart, { data }) {
    // here you can access things inside data from DataPluginStart (see src/plugins/data/server/plugin.ts)
  }

  public stop() {
    // called when plugin is torn down during Kibana's shutdown sequence
  }
}

```

---

<div class="post-metadata">

**Author:** ![lukeelmers](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukeelmers/32/35230_2.png) [@lukeelmers](https://discuss.elastic.co/u/lukeelmers)\
**Post date:** [January 19, 2021, 5:10pm UTC](https://discuss.elastic.co/t/make-es-queries-from-my-custom-kibana-plugin/261416/8 "2021-01-19T17:10:49Z")

</div>

If your main objective is to query ES, you may also want to check out the code in the search example plugin at `examples/search_examples`.

Specifically there are some examples of client-side usage with both the high-level and low-level search APIs here: [https://github.com/elastic/kibana/blob/master/examples/search\_examples/public/components/app.tsx#L101-L263](https://github.com/elastic/kibana/blob/master/examples/search_examples/public/components/app.tsx#L101-L263)

You can run the example plugin locally by using `yarn start --run-examples` -- it will show "developer examples" in the main nav and there's a UI that shows example request/response bodies that are generated by both services.

---

<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:** [February 16, 2021, 5:10pm UTC](https://discuss.elastic.co/t/make-es-queries-from-my-custom-kibana-plugin/261416/9 "2021-02-16T17:10:57Z")

</div>

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