I have been trying to figure out how to get the raw elastic data into my new visualisation (i.e. I don't want aggregations, I want the index data itself). I have a previous thread where I outline what I am trying to achieve. Thanks to the help from Luke there and some of the examples he gave, I have been trying to create a custom handler, but I'm sure what the structure of it should look like.
Luke pointed me in the direction of this empty request handler, and said the arguments it receives are located here, and that I can query elastic using the elastic client library.
However I'm unsure how to piece this altogether. I tried creating a simple handler to ping elasticsearch for me using the examples, but Kibana crashes with the following error: The elasticsearch npm module is not designed for use in the browser. Please use elasticsearch-browser
I can try switching to elasticsearch-browser
, but given that elasticsearch
is what is state in the documentation, I think my implementation is just incorrect.
Can anyone help with why I am seeing this error, and if my current approach is correct? My code is below:
import { VisRequestHandlersRegistryProvider } from 'ui/registry/vis_request_handlers';
const { elasticsearch } = require('elasticsearch');
const client = new elasticsearch .Client({
host: 'localhost:9200',
log: 'trace'
});
const elasticRequestHandlerProvider = function () {
return {
name: 'elastsearchRequestHandler',
handler: function (partialRows, metricsAtAllLevels, index, visParams, timeRange, query, filters, uiState, inspectorAdapters, queryFilter, forceFetch) {
return new Promise((resolve) => {
client.ping({
// ping usually has a 3000ms timeout
requestTimeout: 1000
}, function (error) {
if (error) {
console.trace('elasticsearch cluster is down!');
} else {
console.log('All is well!');
}
});
//Do stuff in here to handle the request. See how courier does it
resolve();
});
}
};
};
VisRequestHandlersRegistryProvider.register(elasticRequestHandlerProvider);
export { elasticRequestHandlerProvider };