# Getting a hold of elastic data within Kibana Plugin

**URL:** <https://discuss.elastic.co/t/getting-a-hold-of-elastic-data-within-kibana-plugin/128606>\
**Category:** Kibana\
**Created:** [April 18, 2018, 10:15pm UTC](https://discuss.elastic.co/t/getting-a-hold-of-elastic-data-within-kibana-plugin/128606 "2018-04-18T22:15:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![JustInTime](https://avatars.discourse-cdn.com/v4/letter/j/e495f1/32.png) [@JustInTime](https://discuss.elastic.co/u/JustInTime)\
**Post date:** [April 18, 2018, 10:15pm UTC](https://discuss.elastic.co/t/getting-a-hold-of-elastic-data-within-kibana-plugin/128606/1 "2018-04-18T22:15:40Z")

</div>

I've been developing a ReactJS based Kibana plugin and have been trying to search my elastic search data within the plugin. Does anyone know what's the best way to approach this? I attempted to use the elastic API but I ran into cross-origin issues and felt like it wouldn't be secure editing the elastic config file to allow cross origin data. I did some looking around and found that I can possibly use the elasticsearch.js library but I haven't figured out how to implement it. In addition, I'm not sure if its usable within a plugin.

---

<div class="post-metadata">

**Author:** ![Stacey\_Gammon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stacey_gammon/32/14025_2.png) [@Stacey\_Gammon](https://discuss.elastic.co/u/Stacey_Gammon)\
**Post date:** [April 19, 2018, 4:46pm UTC](https://discuss.elastic.co/t/getting-a-hold-of-elastic-data-within-kibana-plugin/128606/2 "2018-04-19T16:46:00Z")

</div>

Couple ways to do this.

Take the approach time series visual builder uses and query elasticsearch directly (from the server) and exposing this to the client via an API. Some code for reference:

- using `const { callWithRequest } = req.server.plugins.elasticsearch.getCluster('data');` in  
[https://github.com/elastic/kibana/blob/master/src/core\_plugins/metrics/server/lib/vis\_data/get\_series\_data.js#L6](https://github.com/elastic/kibana/blob/master/src/core_plugins/metrics/server/lib/vis_data/get_series_data.js#L6)

Second way is to do what many visualization plugins do and make use of the client side Courier using SearchSource (see [https://github.com/elastic/kibana/blob/master/src/ui/public/vis/request\_handlers/courier.js](https://github.com/elastic/kibana/blob/master/src/ui/public/vis/request_handlers/courier.js)). This might be too heavy handed for your approach based on what you are querying for. The courier code is also in quite a bit of flux as it's old code and needs to be refactored and de-angularized. So you might be better off, depending on your needs, going with the first approach.

---

<div class="post-metadata">

**Author:** ![JustInTime](https://avatars.discourse-cdn.com/v4/letter/j/e495f1/32.png) [@JustInTime](https://discuss.elastic.co/u/JustInTime)\
**Post date:** [April 19, 2018, 8:58pm UTC](https://discuss.elastic.co/t/getting-a-hold-of-elastic-data-within-kibana-plugin/128606/3 "2018-04-19T20:58:15Z")

</div>

Are there any examples on how I can use `const { callWithRequest } = req.server.plugins.elasticsearch.getCluster('data');`. What would be the command to see how many hits there are in a cluster for a query I am searching.

---

<div class="post-metadata">

**Author:** ![JustInTime](https://avatars.discourse-cdn.com/v4/letter/j/e495f1/32.png) [@JustInTime](https://discuss.elastic.co/u/JustInTime)\
**Post date:** [April 20, 2018, 7:16pm UTC](https://discuss.elastic.co/t/getting-a-hold-of-elastic-data-within-kibana-plugin/128606/4 "2018-04-20T19:16:17Z")

</div>

I have figured this out by using some server side code that handles requests and search elastic search by using the elasticsearch.js plugin.

---

<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:** [May 18, 2018, 7:16pm UTC](https://discuss.elastic.co/t/getting-a-hold-of-elastic-data-within-kibana-plugin/128606/5 "2018-05-18T19:16:32Z")

</div>

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