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'
});
server.route({
path: '/api/HelloWorld/search_test/{searchterm}',
method: 'GET',
handler(req, reply) {
const query = req.params.searchterm;
client.search({
q: query,
index: '<index_name>',
}).then(function (body) {
var hits = body.hits.hits;
}, function (error) {
console.trace(error.message);
});
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: response.data });
window.alert(this.state.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,
Aditya