client.ping() returns error ResponseError: parsing_exception.
'use strict'
const { Client } = require('@elastic/elasticsearch')
const client = new Client({ node: 'http://localhost:9200' })
client.ping({
requestTimeout: 20000,
}, function (error) {
if (error) {
console.error('Elasticsearch cluster is down!, ' + error);
} else {
console.log('Everything is ok');
}
});
A successful connection. :)
I can access the server by going to the url in the browser. Also, I've indexed a couple documents from node as well -code which ran after I get the error being discussed.
When running ./bin/elasticsearch, I get
OpenJDK 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release. Version: 7.0.0, Build: default/tar/b7e28a7/2019-04-05T22:55:32.697037Z, JVM: 12
I've been trying various things, to no avail- adjusting timeout, 'use strict', ':9200/', etc. At least I can still use REST. ^_^
Hello!
In the new JavaScript client every option that is not intended for Elasticsearch lives in a second object, your code should be updated as follows:
'use strict'
const { Client } = require('@elastic/elasticsearch')
const client = new Client({ node: 'http://localhost:9200' })
client.ping({}, { requestTimeout: 20000 }, (err, response) => {
...
})
In the response object other than body, statusCode, and headers, you will also find a warnings array and a meta object, which should help you debug issues.
In this case, warnings contained the following message: 'Client - Unknown parameter: "requestTimeout", sending it as query parameter'.
Thanks, @delvedor, you rock!! It doesn't throw an error anymore. How did you know those specifics? I looked at the API reference, but it didn't help me, really. Also, I would think each of those arguments are supposed to be arrays.
How did you know those specifics?
I'm the author of the library 馃槃
I looked at the API reference, but it didn't help me, really
I suggest you take a look also to the usage section :)
https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/client-usage.html#_request_specific_options
I'm the author of the library 馃槃
Got it, haha!
I did look at that section, but I still don't understand a few things (that's on me, I know). For instance, I didn't see a ping example in the Usage Section- but I do see how there's a second object for options for request (client.search). I'm guessing most client methods are set up in this way then. Thanks again, for that quick support fix.
Now I'm seeing where you specified this. Got it.
I'm guessing most client methods are set up in this way then.
Every client method support the same request options :)
In version 7.8.x the ping() always returns a response error with code 403 while the server is perfectly fine: It answers regular requests.
Also, for some reason await does not seem to work on ping() - while it does as expected with .search() etc.
I think there really should be a working example in the doc.
I can't make it work and there are no recent examples on SO or anywhere I could see...
Pls advise.
@oscar6echo are you using a custom Elasticsearch user? If you are getting a 403 back it might be a permissions issue.
What client are you using? The new one or the legacy one?
Which version of Elasticsearch?
Please also add a snippet of code to reproduce your issue, feel free to open a separate issue.
@delvedor thanks for your quick reply.
I use version "@elastic/elasticsearch": "^7.8.0" and "@nestjs/elasticsearch": "^7.1.0", in a typescript nestjs app.
So in the code below elasticsearchService is a thin wrapper of @elastic/elasticsearch's Client.
Here is the snippet:
async ping(): Promise<object> {
try {
const data = await this.elasticsearchService.ping();
const res = data.body;
return { pong: res };
} catch (err) {
throw new ElasticException(err);
}
}
I just tried it on an Elasticsearch without any access rights and it worked !
{ res: true }
The same code with a reader role (declared via kibana) on one index fails with error 403.
So it would mean that .ping() is not allowed to reader roles !... I find it surprising.
Do you know/confirm ?
BTW: Thx for the lib. It is in general very convenient :clap:
BTW2: I did not open a new issue if it turns out it is only a matter of access rights.
@oscar6echo for running a ping request you need the cluster monitor permissions :)
@delvedor Just checked and on my Elastic the exact name is monitoring_user.
It worked !
Thx a lot for you quick and precise answer.
Most helpful comment
Hello!
In the new JavaScript client every option that is not intended for Elasticsearch lives in a second object, your code should be updated as follows:
In the
responseobject other than body, statusCode, and headers, you will also find a warnings array and a meta object, which should help you debug issues.In this case, warnings contained the following message:
'Client - Unknown parameter: "requestTimeout", sending it as query parameter'.