Requesting Elasticsearch from Node times out
Asked Answered
F

6

22

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.

Forefend answered 14/3, 2014 at 13:25 Comment(7)
To verify that it is not a network issue, can you try and run a curl command from the same machine you are running Node.js on? e.g. curl -XGET 'my-address:9200'Bondwoman
@Bondwoman Did thatn right now, connected perfectly. By the way, ES version is 0.90.5Forefend
Did you tried with http.. I see https in your code.. Pls check againIridescence
@Sidharthan // also tried without protocol part and trailing slashes, and tried normal HTTP tooForefend
Got the same error, can curl it perfectly but after some time this error...Grande
Also getting the error. Did anyone discover a solution since the question was asked? @SlowHarryPetulah
I am having the same issue as well. I cannot find any documentation on this issue.Anneal
P
18

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.

Petulah answered 16/9, 2014 at 20:54 Comment(3)
Tried that and it just timed out at 60000ms instead of 30000ms. ElasticSearch shouldn't be timing out at all.Anneal
It's a get by ID on a very tiny index (5 documents with 1 short string field each). It wouldn't take that long even on gigabytes of data.Forefend
60_000 ms = 1 minute, not 10Hohenstaufen
J
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"
});
Jataka answered 19/8, 2014 at 11:46 Comment(2)
Thank you, you just saved my life!Wiredraw
(the issue is also with Elastic Cloud version 6.2)Wiredraw
P
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.

Petr answered 1/4, 2016 at 9:9 Comment(2)
Your second link is expired.Ellington
Also based on this issue <github.com/elastic/elasticsearch-js/issues/770> I think you should also use requestTimeout instead of timeout in operation-based timeouts. Plus, using timeout will return 503.Ellington
P
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.

Phatic answered 6/4, 2015 at 12:9 Comment(0)
H
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.
Howler answered 28/5, 2018 at 19:43 Comment(0)
C
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.

Coheman answered 7/1, 2022 at 23:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.