# Elasticsearch connection

**URL:** https://discuss.elastic.co/t/elasticsearch-connection/333621
**Category:** Kibana
**Tags:** kibana-plugin-development
**Created:** [May 17, 2023, 4:14am UTC](https://discuss.elastic.co/t/elasticsearch-connection/333621 "2023-05-17T04:14:18Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![rodrigo\_Ceron](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rodrigo_ceron/32/120674_2.png) [@rodrigo\_Ceron](https://discuss.elastic.co/u/rodrigo_Ceron)
#### Post date: [May 17, 2023, 4:14am UTC](https://discuss.elastic.co/t/elasticsearch-connection/333621/1 "2023-05-17T04:14:18Z")

</div>

Hello everyone,

I'm developing a custom plugin and I would like to connect to Elasticsearch side client, but the link I'm using ([Elasticsearch service | Kibana Guide [8.7] | Elastic](https://www.elastic.co/guide/en/kibana/8.7/elasticsearch-service.html)) is not working and the documentation is not up to date.  
How can I connect to Elasticsearch and show data ?

---

<div class="post-metadata">

### Author: ![devon.thomson](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/devon.thomson/32/85468_2.png) [@devon.thomson](https://discuss.elastic.co/u/devon.thomson)
#### Post date: [May 17, 2023, 8:04pm UTC](https://discuss.elastic.co/t/elasticsearch-connection/333621/2 "2023-05-17T20:04:04Z")

</div>

Are you trying to access `core.elasticsearch` from inside a `public` directory, or from inside the `server` directory of your plugin?

It should be accessible from a `plugin.ts` inside the `server` directory.

---

<div class="post-metadata">

### Author: ![rodrigo\_Ceron](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rodrigo_ceron/32/120674_2.png) [@rodrigo\_Ceron](https://discuss.elastic.co/u/rodrigo_Ceron)
#### Post date: [May 17, 2023, 11:36pm UTC](https://discuss.elastic.co/t/elasticsearch-connection/333621/3 "2023-05-17T23:36:03Z")

</div>

I'm trying both approaches, but the core.elasticsearch object doesn't exist in the "public" directory. However, it does exist in the "server" directory. The problem is that when I access it from the "server" directory, it returns undefined.

My question is: Is it necessary to create a separate connection to Elasticsearch in my plugin, or is the Elasticsearch connection already configured by default?

---

<div class="post-metadata">

### Author: ![tsullivan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tsullivan/32/31077_2.png) [@tsullivan](https://discuss.elastic.co/u/tsullivan)
#### Post date: [June 1, 2023, 12:13am UTC](https://discuss.elastic.co/t/elasticsearch-connection/333621/4 "2023-06-01T00:13:10Z")

</div>

> [@rodrigo\_Ceron](#):
>
> My question is: Is it necessary to create a separate connection to Elasticsearch in my plugin, or is the Elasticsearch connection already configured by default?

The elasticsearch connection is already configured and available to your plugin, but on the client side you'll want to use the `data` plugin dependency to access it.  
Try using the developer examples by running Kibana from source with `yarn start --run-examples`, go to the **Developer examples** page from the side navigation, and look for the "Search Examples" plugin.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/9/f/9f67064182d92888aa4ad3fd458827a4a5545d21.jpeg)

---

<div class="post-metadata">

### Author: ![tsullivan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tsullivan/32/31077_2.png) [@tsullivan](https://discuss.elastic.co/u/tsullivan)
#### Post date: [June 1, 2023, 12:18am UTC](https://discuss.elastic.co/t/elasticsearch-connection/333621/5 "2023-06-01T00:18:24Z")

</div>

> [@rodrigo\_Ceron](#):
>
> However, it does exist in the "server" directory. The problem is that when I access it from the "server" directory, it returns undefined.

Can you elaborate on what you mean by that? There is a service provided for Elasticsearch communications under the `core` object in your plugin's setup and start methods:

**`plugins/my_plugin/server/plugin.ts`:**

```auto
export class MyPlugin implements Plugin<void, void, SetupDeps, StartDeps> {
  constructor(initializerContext: PluginInitializerContext) {}

  public setup(core: CoreSetup, deps: SetupDeps) {
    core.elasticsearch; // ElasticsearchServiceSetup

    return {};
  }

  public start(core: CoreStart, deps: StartDeps) {
    core.elasticsearch; // ElasticsearchServiceStart

    return {};
  }

  public stop() {}
}

```

---

<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: [June 29, 2023, 12:19am UTC](https://discuss.elastic.co/t/elasticsearch-connection/333621/6 "2023-06-29T00:19:20Z")

</div>

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