Elasticsearch connection

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) is not working and the documentation is not up to date.
How can I connect to Elasticsearch and show data ?

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.

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?

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.

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:


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() {}

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