Hi,
I'm upgrading a script from JSReport 1.10.1 (with node 8.15.1) to JSReport 2.11.0 (with node 12.22.1).
The 1.10.1 script begins like this and then continues with running queries to extract data from an Elasticsearch index for output to a CSV file.
(function() {
'use strict';
var config = require('Configuration.json');
var elasticsearch = require('elasticsearch');
var esClient = new elasticsearch.Client({
host: config.esURL,
log: {
"type": config.esLog.type,
"level": config.esLog.level,
"path": config.esLog.path
}
});
// simple test for ES connectivity - fetch cluster health
esClient.cluster.health({},function(err,resp,status) {
console.log("-- Client Health -- resp",resp);
console.log("-- Client Health -- err",err);
console.log("-- Client Health -- status",status);
});
That works and returns data from Elasticsearch telling me the status of the Elasticsearch cluster; knowing the cluster is healthy we then proceed to run a query to get the data from an Elasticsearch index that's needed for the output file. And that's all good and it works fine in 1.10.1.
In 2.11.0, I've modified it slightly to this:
function beforeRender(req, res, done) {
var config = require('Configuration.json');
var elasticsearch = require('@elastic/elasticsearch');
var esClient = new elasticsearch.Client({
node: config.esURL,
auth: {
username: config.user,
password: config.password
}
});
// simple test for ES connectivity - fetch cluster health
esClient.cluster.health({},function(err,resp,status) {
console.log("-- Client Health -- resp",resp);
console.log("-- Client Health -- err",err);
console.log("-- Client Health -- status",status);
});
Here the call to get the Elasticsearch cluster health information seems to do nothing; apparently it doesn't run. And that's my issue; I don't know why this is behaving differently in 2.11.0.
So far I've been unable to get anything back from the Elasticsearch client using either this type of request or a query to get data.
console log shows that esClient is looking correct; and if I use invalid values when I define esClient (e.g. a URL that's not valid) then I do get error messages back. So defining esClient seems to be working ok.
These are the configuration options used with 2.11.0 to start JSReport:
var jsReportConf = {
'httpPort': '3100',
'store': {
'provider': 'fs'
},
'blobStorage': {
'provider': 'fs'
},
'templatingEngines': {
'numberOfWorkers': 2,
'reportTimeout': 180000,
'allowedModules': '*'
},
'extensions': {
'scripts': {
'timeout': 180000
},
'express': {
'renderTimeout': 600000
},
},
'reportTimeout': 180000,
'logger': {
'console': {
'transport': 'console',
'level': 'debug'
},
'file': {
'transport': 'file',
'level': 'debug',
'filename': 'logs/JSReport-reporter.log'
},
'error': {
'transport': 'file',
'level': 'error',
'filename': 'logs/JSReport-error.log'
}
},
'allowLocalFilesAccess': true
};
The Elasticsearch package I'm using has changed as well (from elasticsearch 16.5 to @elastic/elasticsearch 7.12) but outside JSReport I'm able to use node.js to run essentially the code same as I've shown here and it gets the data from Elasticsearch without any problems.
I've read the breaking changes documentation for 2.0 but assume I've missed (or misunderstood) something, how would I get this to work in 2.11.0 the same way that it works with 1.10.1 ?
Thanks,
-Derek