Make ES Queries from my Custom Kibana Plugin

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

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 for the documentation

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

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
in particular the state containers example https://github.com/elastic/kibana/tree/master/examples/state_containers_examples provides an example on how to use the data plugin

The official documentation seems to be updated: 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

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

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

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
  }
}

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

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.

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