javascript 从节点请求 Elasticsearch 超时

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22406300/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 23:05:09  来源:igfitidea点击:

Requesting Elasticsearch from Node times out

javascriptnode.jselasticsearchrequest-timed-out

提问by Kroltan

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 _headplugin, 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:

我正在使用官方 Javascript 客户端设置一个简单的 Node.js REST 服务来与 Elasticsearch 交互。我在本地运行此代码,但集群位于远程。当我浏览浏览器时,使用_head插件,我可以毫无问题地连接 ES 和查询。但是,通过 Javascript 客户端这样做会使所有请求超时。我设置了 ElasticSearch 对象,但是向它发送任何请求都不起作用。我不认为这是网络问题,因为我可以通过浏览器访问 ES。这就是我请求某些东西的方式,一个非常基本的获取:

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.

这失败并显示一条简单的错误消息 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.

我在这里错过了什么吗?我已经阅读了客户端文档,这对于客户端来说似乎是基本的“hello world”。

回答by Lorien

Try extending the requestTimeoutparameter when instantiating the ES Client.

尝试在实例化 ES 客户端时扩展requestTimeout参数。

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.

我有一个长时间运行的过程,只花了不到 10 分钟。通过将 requestTimeout 值设为 60000(10 分钟),该过程可以完成而不会超时。

回答by oliviercuyp

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

由于sniffOnStart ,我们在 QBox 上也遇到了这个问题。试试这个配置:

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:

您会看到添加的节点 ip 是私有 ip。在我们这边,我们决定禁用嗅探并手动添加公共节点主机地址数组,如下所示:

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

回答by fritz

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

请在此处查看有关此问题的信息:https: //github.com/elastic/elasticsearch-js/issues/186

I guess we need to use the requestTimeoutvariable as mentioned above.

我想我们需要使用requestTimeout上面提到的变量。

回答by ambodi

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

关于弹性搜索中的超时,您需要区分两种类型的超时:

  • 初始化超时: 初始化 ES: 时requestTimeoutpingTimeout两者默认为 30000ms。阅读更多:弹性搜索文档中的配置文档

  • 基于操作的超时:许多操作,例如bulkcreatedeleteindex也可以设置timeout。假设你有一个巨大的批量对象要插入,你可以只设置基于操作的超时:弹性搜索文档

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

您应该知道基于操作的超时会覆盖初始化RequestTimeout

回答by xs2rashid

Check following items if you see

如果您看到,请检查以下项目

Discover: Request Timeout after 30000ms

发现:30000 毫秒后请求超时

  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.
  1. 确保 Elasticsearch CPU/内存没有阻塞
  2. 如果查询窗口的数据很多,那么有可能请求在 30000ms 内超时 在 kibana.yml 中增加 kibana 的超时时间 --> elasticsearch.requestTimeout: 120000 重启 kibana 服务
  3. 减少 kibana 仪表板加载的数据量发现:管理下的样本大小 - 高级设置 --> 相应地更改值
  4. 如果中间有任何负载均衡器,那么也增加
    LB 的超时设置。