Good day, I have searched high and low for an example that works in 2021 (ES 7.11) on how to implement ES querying from a Custom Kibana Plugin. The use case is there are config files stored in an index that we would like to CRUD to via a custom plugin. I have seen that elasticsearch-js shouldn't/can't be used client side and there seems to be no other documentation on how to go about this.
So far I have a test plugin that works with their example like so:
const onClickHandler = () => {
indent preformatted text by 4 spaces
// Use the core http service to make a response to the server API.
http.get('/api/test_plugin/example').then((res) => {
console.log(res);
setTimestamp(res.time);
// Use the core notifications service to display a success message.
notifications.toasts.addSuccess(
i18n.translate('testPlugin.dataUpdated', {
defaultMessage: 'Data updated',
})
);
});
};
However, I do not know how to access the indices from my ReactJS based plugin. If there is any documentation or package I am not aware of, please let me know. Many previous questions had dead links or redirected to outdated documentation.
On the server side of your plugin (where you implement your route /api/test_plugin/example), you can get access to an ES client via context.core.elasticsearch.client.asCurrentUser to do ES queries, then pass the results to the client.
I'm building something similar right now for educational purposes.
There are multiple ways to achieve this but I chose to use Axios due to familiarity. On your client side you want to access your server side route by doing something like.
Thanks for the reduced example, @aaron-nimocks . It's possible to use axios, the recommended way is to use the core http service (as you seem to do already in your original post). So if you start from scratch now, it makes sense to stick with that (it will take care of xsrf protection and the like automatically)
Maybe installing my plugin and seeing how it works will help since it's doing something similar. Just want to make clear that this is not even close to being finished and wasn't meant for human consumption.
It's just a project I am using to help learn everything, same as you are doing. This one allows you to select any index pattern, then select the fields you want to view, and then finally goes get's the data to fill a table. The pre-search filters and any edit functionality has not been added yet.
Hopefully this will help with your learning curve.
That might work, however make sure to check each minor version upgrade whether it still works. The console API is not considered public AFAIK so we don't make any effort to keep it backwards compatible.
There is an example in that plug-in called get_index_list.ts I believe and would look at swapping to that when you start getting comfortable with the code.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.