Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Requesting Elasticsearch from Node times out

Tags:

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.

like image 200
Kroltan Avatar asked Mar 14 '14 13:03

Kroltan


People also ask

How do I increase Elasticsearch timeout?

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.

What is request timeout in NodeJS?

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.

Can we use Elasticsearch with NodeJS?

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 .


1 Answers

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.

like image 98
Lorien Avatar answered Sep 27 '22 20:09

Lorien