How to call elastic search API from custom Kibana Plugin

Hello Team,

I have created a custom plugin (using plugin generator) and added control like textbox ( I am using elastic UI framework). I am able to read the data from these UI controls.

I want to execute a search request based on the user inputs, Could you please let me know what is the recommended way to communicate with Elasticsearch and get the data. Currently i am making a rest call from main.js (my_plugin_name/public/components/main/main.js)

Git Url : my_test_plugin

Could you please let me know if i am missing something.
Thanks in advance for your help and support.

Thank you,

You could use the elasticsearch javascript client.

An example of how it is used in Kibana, you can see here:

Thank you thomasneirynvk.
I tried to use elasticsearch.js , however I got the error that it is not allowed to use in browser.

While searching I found below link.

Any thoughts , suggestions about using above lib.

Just FYI
I am using Kibana 6.5 and code generated by plugin generator is in react.js

Please let me know if I am missing something.
Sorry if I am asking too basic information, I am new to Elasticsearch and UI development.

Thank you very much for your help and support.

Thank you,

Hello Team,

I was able to call elasticsearch backend using elasticsearch.js
I added server route and called the method from route file and passed the parameters using path parameters.

import elasticsearch from 'elasticsearch'

export default function (server) {

	const client = new elasticsearch.Client({
		  host: 'localhost:9200',
		  log: 'trace'

    path: '/api/HelloWorld/search_test/{searchterm}',
    method: 'GET',
    handler(req, reply) {
      const query =  req.params.searchterm;{
		 q: query,
		 index: '<index_name>',
		}).then(function (body) {
			var hits = body.hits.hits;
		}, function (error) {
			reply({ response: body.hits.hits });


and called this method from main.js

const { httpClient } = this.props;
    httpClient.get('../api/HelloWorld/search_test/'+this.state.searchTerm).then((response) => {
      this.setState({ resp: });

Code repo:
Custom Kibana Plugin

Could you please let me know if this is the right way to do it or if i am missing something.

Thank you very much for your help and support.

Thank you,

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