I am setting up a simple Node.js REST service to interface with Elasticsearch, using the official Javascript client. I'm running this code locally, but the cluster is located remotely. When I go trough the browser, with the _head
plugin, I can connect ES and query with no problem. However, doing so via the Javascript client times out all requests. I set up the ElasticSearch object, but sending any request to it simply doesn't work. I don't think it's a network issue, because I can access ES trough the browser. This is how I request something, a very basic get:
var elasticsearch = require("elasticsearch"); var es = new elasticsearch.Client({ host: "https://my-address:9200/", // also tried without protocol part and trailing slashes log: "error", sniffOnStart: true }); es.get({ index: "things", type: "someThing", id: "42" }).then(doSomeStuff, handleStuffFailed);
This fails with a simple error message Errror: Request timeout after 30000ms.
Am I missing something here? I've read trough the client docs, and this seems like the basic "hello world" for the client.
By default, the timeout value is set to 10 secs. If one wants to change the global timeout value, this can be achieved by setting the flag timeout=your-time while creating the object.
By default, NodeJS has a timeout value of 120 seconds. Sometimes you may need to increase request timeout in NodeJS to process long running requests.
Using the elasticsearch module in node we can easily connect to and interact with our elasticsearch cluster. We'll create one file for the connection code which we can then use in all our subsequent code using Node's require method. Copy this code and save it as connection. js .
Try extending the requestTimeout parameter when instantiating the ES Client.
client = new elasticsearch.Client({ host : 'http://localhost:9200', requestTimeout: 60000 });
I had a long-running process which took just under 10 minutes. By making the requestTimeout value 60000 (10 mins) the process could complete without timing out.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With