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
Requesting Elasticsearch from Node times 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 _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:
我正在使用官方 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 requestTimeout
variable as mentioned above.
我想我们需要使用requestTimeout
上面提到的变量。
回答by ambodi
Regarding timeouts in elastic search, you need to differentiate between two types of timeouts:
关于弹性搜索中的超时,您需要区分两种类型的超时:
Initialization timeout: When you initialize ES:
requestTimeout
,pingTimeout
both of which defaults to 30000ms. Read more: Configuration documentation in elastic search documentationOperation-based timeouts: Many operations such as
bulk
,create
,delete
,index
can settimeout
too. Say if you have a huge bulk object to insert, you can just set operation-based timeouts: Elastic Search documentations
初始化超时: 初始化 ES: 时
requestTimeout
,pingTimeout
两者默认为 30000ms。阅读更多:弹性搜索文档中的配置文档基于操作的超时:许多操作,例如
bulk
、create
、delete
、index
也可以设置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 毫秒后请求超时
- Make sure Elasticsearch CPU/Memory is not chocking
- 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
- Decrease ammount of data loaded by kibana dashboard discover:sampleSize under Management - Advanced settings --> Change the value accordingly
- If there is any Load Balancer in between then increase timeout settings
from LB as well.
- 确保 Elasticsearch CPU/内存没有阻塞
- 如果查询窗口的数据很多,那么有可能请求在 30000ms 内超时 在 kibana.yml 中增加 kibana 的超时时间 --> elasticsearch.requestTimeout: 120000 重启 kibana 服务
- 减少 kibana 仪表板加载的数据量发现:管理下的样本大小 - 高级设置 --> 相应地更改值
- 如果中间有任何负载均衡器,那么也增加
LB 的超时设置。