21

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.

6 Answers6

17

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.

Lorien
  • 442
  • 4
  • 6
8

We also had this issue on QBox because of sniffOnStart. Try with this config:

var es = new elasticsearch.Client({
    host: "my-address:9200",
    log: "trace",
    sniffOnStart: true
});

You'll see that the added nodes ip are the private ip. On our side, we decided to disable the sniffing and add manually the array of public node host addresses like this:

var es = new elasticsearch.Client({
    hosts: ["my-address1:9200", "my-address2:9200", "my-address3:9200"],
    log: "error"
});
oliviercuyp
  • 205
  • 3
  • 5
3

Regarding timeouts in elastic search, you need to differentiate between two types of timeouts:

You should know that operation-based timeouts overwrite the initializationRequestTimeout.

ambodi
  • 6,116
  • 2
  • 32
  • 22
2

Check here regarding this issue: https://github.com/elastic/elasticsearch-js/issues/186

I guess we need to use the requestTimeout variable as mentioned above.

fritz
  • 698
  • 6
  • 12
1

Check following items if you see

Discover: Request Timeout after 30000ms

  1. Make sure Elasticsearch CPU/Memory is not chocking
  2. If there is a lot of data for query window then it is possible that request times out within 30000ms Increase timeout for kibana in kibana.yml --> elasticsearch.requestTimeout: 120000 Restart kibana service
  3. Decrease ammount of data loaded by kibana dashboard discover:sampleSize under Management - Advanced settings --> Change the value accordingly
  4. If there is any Load Balancer in between then increase timeout settings
    from LB as well.
xs2rashid
  • 953
  • 12
  • 16
0

If you're running more than one node per server, try locking down the number of processors that each jvm gets access to. we had this problem and doing this fixed it. We think one node was using too much system resources and it would cause the other node on the same server to be slow to respond to the master node when queried for status.